Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 1.94 KB

File metadata and controls

74 lines (56 loc) · 1.94 KB

Lint your nx project commits

@commitlint/config-nx-scopes

Shareable commitlint config enforcing nx project and workspace names as scopes. Use with @commitlint/cli and @commitlint/prompt-cli.

Getting started

npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli
echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js

Filtering projects

You can filter projects by defining a filter function as the second parameter to the getProjects function. The function will be called with the each projects' name, type, and tags. You can return a boolean to indicate whether the project should be included or not.

As an example, the following code demonstrates how to select only applications that are not end-to-end tests.

In your .commitlintrc.js file:

const {
  utils: {getProjects},
} = require('@commitlint/config-nx-scopes');

module.exports = {
  rules: {
    'scope-enum': async (ctx) => [
      2,
      'always',
      [
        ...(await getProjects(
          ctx,
          ({name, type}) => !name.includes('e2e') && type == 'application'
        )),
      ],
    ],
  },
  // . . .
};

Examples

❯ cat commitlint.config.js
{
  extends: ['@commitlint/config-nx-scopes']
}

❯ tree packages

packages
├── api
├── app
└── web

❯ echo "build(api): change something in api's build" | commitlint
⧗   input: build(api): change something in api's build
✔   found 0 problems, 0 warnings

❯ echo "test(foo): this won't pass" | commitlint
⧗   input: test(foo): this won't pass
✖   scope must be one of [api, app, web] [scope-enum]
✖   found 1 problems, 0 warnings

❯ echo "ci: do some general maintenance" | commitlint
⧗   input: ci: do some general maintenance
✔   found 0 problems, 0 warnings

Consult docs/rules for a list of available rules.