@commitlint/cli
picks up configuration from ./commitlint.config.js
.
The file is expected
- to contain valid JavaScript
- export a configuration object
- adhere to the schema outlined below
type Config = {
/*
* Resolveable ids to commitlint configurations to extend
*/
extends?: string[];
/*
* Resolveable id to conventional-changelog parser preset to import and use
*/
parserPreset?: string;
/*
* Resolveable id to package, from node_modules, which formats the output.
*/
formatter: string;
/*
* Rules to check against
*/
rules?: {[name: string]: Rule};
/*
* Custom list of Messages to Ignore, string values will be compiled as RegExp
*/
ignoredMessages?: Array<string | RegExp | string => boolean>;
/*
* If this is true we will not use any of the default is-ignored rules
*/
disableDefaultIgnoredMessages?: boolean;
}
const Configuration: Config = {
/*
* Resolve and load @commitlint/config-conventional from node_modules.
* Referenced packages must be installed
*/
extends: ['@commitlint/config-conventional'],
/*
* Resolve and load conventional-changelog-atom from node_modules.
* Referenced packages must be installed
*/
parserPreset: 'conventional-changelog-atom',
/*
* Resolve and load @commitlint/format from node_modules.
* Referenced package must be installed
*/
formatter: '@commitlint/format',
/*
* Any rules defined here will override rules from @commitlint/config-conventional
*/
rules: {
'type-enum': [2, 'always', ['foo']]
},
/*
* These RegExp and functions are used to ignore messages that shouldn't be linted
*/
ignoredMessages: [
'^Entire Message to Ignore$',
/^(ci|github):/,
(commit) => commit === ''
],
/*
* If this is true then the default ignores like `Merge commit` are not ignored
* and will cause commitlint to fail
*/
disableDefaultIgnoredMessages: true
};
module.exports = Configuration;
Every commitlint configuration can extend other commitlint configurations.
Specify configurations to extend via the .extends
key, using ids
that can be resolved by the node resolve algorithm.
This means installed npm packages and local files can be used.
- npm
npm install --save-dev commitlint-config-lerna @commitlint/config-conventional
// commitlint.config.js
module.exports = {
extends: [
'lerna' // prefixed with commitlint-config-*,
'@commitlint/config-conventional' // scoped packages are not prefixed
]
}
- local
// commitlint.config.js
module.exports = {
extends: ['./commitlint.base.js', './commitlint.types.js']
}
// commitlint.types.js, will be picked up by commitlint.config.js
module.exports = {
rules: {
'type-enum': [2, 'always', ['foo']]
}
}
// commitlint.base.js, will be picked up by commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'], // extends can be nested
parserPreset: 'conventional-changelog-atom'
}
The parser preset used to parse commit messages can be configured. Use ids resolveable by the node resolve algorithm.
This means installed npm packages and local files can be used.
- npm
npm install --save-dev conventional-changelog-atom
// commitlint.config.js
module.exports = {
parserPreset: 'conventional-changelog-atom'
}
- local
// commitlint.config.js
module.exports = {
parserPreset: './parser-preset'
}
// parser-preset.js
module.exports = {
parserOpts: {
headerPattern: /^(\w*)\((\w*)\)-(\w*)\s(.*)$/,
headerCorrespondence: ['type', 'scope', 'ticket', 'subject']
}
};
Commitlint can output the issues encountered in different formats, if necessary. Use ids resolvable by the node resolve algorithm.
module.exports = {
formatter: '@commitlint/format'
};
Refer to Rules for a complete list of available rules.