Skip to content

Commit ae88baf

Browse files
committed
docs: update example usage of project filtering with @commitlint/config-nx-scopes
1 parent bc49e93 commit ae88baf

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

@commitlint/config-nx-scopes/readme.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,37 @@ npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli
1212
echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js
1313
```
1414

15-
## Filtering projects by type
15+
## Filtering projects
1616

17-
You can filter projects by type by specifying the project type parameter.
17+
You can filter projects by providing a filter function as the second parameter to `getProjects()`. The function will be called with each projects' `name`, `type`, and `tags`. Simply return a boolean to indicate whether the project should be included or not.
18+
19+
As an example, the following code demonstrates how to select only applications that are not end-to-end tests.
20+
21+
In your .commitlintrc.js file:
22+
23+
```javascript
24+
const {
25+
utils: {getProjects},
26+
} = require('@commitlint/config-nx-scopes');
27+
28+
module.exports = {
29+
rules: {
30+
'scope-enum': async (ctx) => [
31+
2,
32+
'always',
33+
[
34+
...(await getProjects(
35+
ctx,
36+
({name, type}) => !name.includes('e2e') && type == 'application'
37+
)),
38+
],
39+
],
40+
},
41+
// . . .
42+
};
43+
```
44+
45+
Here is another example where projects tagged with 'stage:end-of-life' are not allowed to be used as the scope for a commit.
1846

1947
In your .commitlintrc.js file:
2048

@@ -28,9 +56,15 @@ module.exports = {
2856
'scope-enum': async (ctx) => [
2957
2,
3058
'always',
31-
[...(await getProjects(ctx, 'application'))], // ⬅ or 'library'
59+
[
60+
...(await getProjects(
61+
ctx,
62+
({tags}) => !tags.includes('stage:end-of-life')
63+
)),
64+
],
3265
],
3366
},
67+
// . . .
3468
};
3569
```
3670

0 commit comments

Comments
 (0)