Skip to content

Commit

Permalink
feat: add ability to filter Nx projects in @commitlint/config-nx-scopes
Browse files Browse the repository at this point in the history
Solves: #3152
  • Loading branch information
jaytavares committed Apr 30, 2022
1 parent 20122e8 commit f57dca9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion @commitlint/config-nx-scopes/index.js
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
};

function getProjects(context) {
function getProjects(context, projectType) {
return Promise.resolve()
.then(() => {
const ctx = context || {};
Expand All @@ -24,6 +24,9 @@ function getProjects(context) {
})
.then((projects) => {
return projects
.filter((project) =>
projectType ? project.projectType === projectType : true
)
.filter((project) => project.targets)
.map((project) => project.name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
Expand Down
22 changes: 22 additions & 0 deletions @commitlint/config-nx-scopes/readme.md
Expand Up @@ -12,6 +12,28 @@ npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli
echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js
```

## Filtering projects by type

You can filter projects by type by specifying the project type parameter.

In your .commitlintrc.js file:

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

module.exports = {
rules: {
'scope-enum': async (ctx) => [
2,
'always',
[...(await getProjects(ctx, 'application'))], // ⬅ or 'library'
],
},
};
```

## Examples

```
Expand Down

0 comments on commit f57dca9

Please sign in to comment.