|
| 1 | +# Configuration |
| 2 | + |
| 3 | +`@commitlint/cli` picks up configuration from `./commitlint.config.js`. |
| 4 | + |
| 5 | +The file is expected |
| 6 | + |
| 7 | +* to contain valid JavaScript |
| 8 | +* export a configuration object |
| 9 | +* adhere to the schema outlined below |
| 10 | + |
| 11 | +```ts |
| 12 | +type Config = { |
| 13 | + /* |
| 14 | + * Resolveable ids to commitlint configurations to extend |
| 15 | + */ |
| 16 | + extends?: string[]; |
| 17 | + /* |
| 18 | + * Resolveable id to conventional-changelog parser preset to import and use |
| 19 | + */ |
| 20 | + parserPreset?: string; |
| 21 | + /* |
| 22 | + * Rules to check against |
| 23 | + */ |
| 24 | + rules?: {[name: string]: Rule}; |
| 25 | +} |
| 26 | + |
| 27 | +const Configuration: Config = { |
| 28 | + /* |
| 29 | + * Resolve and load @commitlint/config-angular from node_modules. |
| 30 | + * Referenced packages must be installed |
| 31 | + */ |
| 32 | + extends: ['@commitlint/config-angular'], |
| 33 | + /* |
| 34 | + * Resolve and load conventional-changelog-atom from node_modules. |
| 35 | + * Referenced packages must be installed |
| 36 | + */ |
| 37 | + parserPreset: 'conventional-changelog-atom', |
| 38 | + /* |
| 39 | + * Any rules defined here will override rules from @commitlint/config-angular |
| 40 | + */ |
| 41 | + rules: { |
| 42 | + 'type-enum': [2, 'always', ['foo']] |
| 43 | + } |
| 44 | +}; |
| 45 | + |
| 46 | +module.exports = Configuration; |
| 47 | +``` |
| 48 | + |
| 49 | +## Shareable configuration |
| 50 | + |
| 51 | +Every commitlint configuration can extend other commitlint configurations. |
| 52 | +Specify configurations to extend via the `.extends` key, using ids |
| 53 | +that can be resolved by the node resolve algorithm. |
| 54 | + |
| 55 | +This means installed npm packages and local files can be used. |
| 56 | + |
| 57 | +* npm |
| 58 | + |
| 59 | +``` |
| 60 | +npm install --save-dev commitlint-config-lerna @commitlint/config-angular |
| 61 | +``` |
| 62 | + |
| 63 | +```js |
| 64 | +// commitlint.config.js |
| 65 | +module.exports = { |
| 66 | + extends: [ |
| 67 | + 'lerna' // prefixed with commitlint-config-*, |
| 68 | + '@commitlint/config-angular' // scoped packages are not prefixed |
| 69 | + ] |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +* local |
| 74 | + |
| 75 | + |
| 76 | +```js |
| 77 | +// commitlint.config.js |
| 78 | +module.exports = { |
| 79 | + extends: ['./commitlint.base.js', './commitlint.types.js'] |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +```js |
| 84 | +// commitlint.types.js, will be picked up by commitlint.config.js |
| 85 | +module.exports = { |
| 86 | + rules: { |
| 87 | + 'type-enum': [2, 'always', ['foo']] |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +```js |
| 93 | +// commitlint.base.js, will be picked up by commitlint.config.js |
| 94 | +module.exports = { |
| 95 | + extends: ['@commitlint/config-angular'], // extends can be nested |
| 96 | + parserPreset: 'conventional-changelog-atom' |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +## Parser presets |
| 101 | + |
| 102 | +The parser preset used to parse commit messages can be configured. |
| 103 | +Use ids resolveable by the node resolve algorithm. |
| 104 | + |
| 105 | +This means installed npm packages and local files can be used. |
| 106 | + |
| 107 | +* npm |
| 108 | + |
| 109 | +``` |
| 110 | +npm install --save-dev conventional-changelog-atom |
| 111 | +``` |
| 112 | + |
| 113 | +```js |
| 114 | +// commitlint.config.js |
| 115 | +module.exports = { |
| 116 | + parserPreset: 'conventional-changelog-atom' |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +* local |
| 121 | + |
| 122 | +```js |
| 123 | +// commitlint.config.js |
| 124 | +module.exports = { |
| 125 | + parserPreset: './parser-preset' |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +```js |
| 130 | +// parser-preset.js |
| 131 | +module.exports = { |
| 132 | + parserOpts: { |
| 133 | + headerPattern: /^(\w*)\((\w*)\)-(\w*)\s(.*)$/, |
| 134 | + headerCorrespondence: ['type', 'scope', 'ticket', 'subject'] |
| 135 | + } |
| 136 | +}; |
| 137 | +``` |
| 138 | + |
| 139 | +## Rules |
| 140 | + |
| 141 | +Refer to [Rules](reference-rules.md) for a complete list of available rules. |
0 commit comments