|
| 1 | +## Introduction |
| 2 | + |
| 3 | +[](https://npmjs.com/package/commitlint-plugin-selective-scope) |
| 4 | +[](https://npmjs.com/package/commitlint-plugin-selective-scope) |
| 5 | +[](http://commitizen.github.io/cz-cli/) |
| 6 | +[](https://github.com/semantic-release/semantic-release) |
| 7 | +[](https://travis-ci.com/ridvanaltun/commitlint-plugin-selective-scope) |
| 8 | +[](https://coveralls.io/github/ridvanaltun/commitlint-plugin-selective-scope?branch=master) |
| 9 | +[](https://github.com/ridvanaltun/commitlint-plugin-selective-scope/blob/master/LICENSE) |
| 10 | + |
| 11 | +> Limit scopes per type with regexp and plain text. |
| 12 | +
|
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +npm i commitlint-plugin-selective-scope --save-dev |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +- If a type does not appear in the rule, do not enforce scope |
| 22 | +- If a type appears in the rule with an empty array, do not allow scope |
| 23 | +- If a type appears in the rule with an non-empty array, only allow the values in the array for scope. |
| 24 | +- If the array includes null, the scope is optional. |
| 25 | + |
| 26 | +## Example |
| 27 | + |
| 28 | +```javascript |
| 29 | +module.exports = { |
| 30 | + plugins: ['selective-scope'], |
| 31 | + rules: { |
| 32 | + 'selective-scope': [ |
| 33 | + 2, |
| 34 | + 'always', |
| 35 | + { |
| 36 | + feat: [/^frontend\/[^\/]+$/, 'backend'], |
| 37 | + perf: [], |
| 38 | + ci: [null, 'codebuild', 'jenkins'] |
| 39 | + } |
| 40 | + ] |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +**In the above rules configuration,** |
| 46 | + |
| 47 | +- if the type is `feat`, the scope must be either match the regex `/frontend\/[^\/]+/` or be `backend` |
| 48 | +- if the type if `chore`, the scope is optional and can be anything |
| 49 | +- if the type is `perf`, a scope is not allowed |
| 50 | +- if the type is `ci`, the scope must be `codebuild` or `jenkins` if present, but is not required |
0 commit comments