diff --git a/@commitlint/config-nx-scopes/index.js b/@commitlint/config-nx-scopes/index.js index 491d92ffdf..d68aca95d2 100644 --- a/@commitlint/config-nx-scopes/index.js +++ b/@commitlint/config-nx-scopes/index.js @@ -8,7 +8,7 @@ module.exports = { }, }; -function getProjects(context) { +function getProjects(context, projectType) { return Promise.resolve() .then(() => { const ctx = context || {}; @@ -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)); diff --git a/@commitlint/config-nx-scopes/readme.md b/@commitlint/config-nx-scopes/readme.md index ad3e92c762..489b09c9ff 100644 --- a/@commitlint/config-nx-scopes/readme.md +++ b/@commitlint/config-nx-scopes/readme.md @@ -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 ```