commitlint-plugin-function-rules
Version:
commitlint plugin to use functions as rule value
103 lines (74 loc) • 5.18 kB
Markdown
# [**commitlint**][commitlint] plugin function rules <!-- omit in toc -->
[**commitlint**][commitlint] plugin to use functions as rule value.
- Create custom function, `sync` or `async`, as rule value.
- Create rules that are based on the commit message.
- Write rules with regular expressions.
- Use the same rules that are [available in **commitlint**][commitlint].
---
[](https://www.npmjs.com/package/commitlint-plugin-function-rules)
[](https://www.npmjs.com/package/commitlint-plugin-function-rules)
[](https://nodejs.org/en/about/releases/)
[](https://renovatebot.com)
[](https://github.com/semantic-release/semantic-release)
[](https://codecov.io/gh/vidavidorra/commitlint-plugin-function-rules)
[](LICENSE.md)
- [Install](#install)
- [Usage](#usage)
- [Contributing](#contributing)
- [Security policy](#security-policy)
- [License](#license)
## Install
```shell
npm install --save-dev commitlint-plugin-function-rules @commitlint/cli @commitlint/config-conventional
```
## Usage
Use this plugin in your project's [**commitlint**][commitlint] configuration by specifying it as item in the `plugins` array. All rules have same name as rules that are [available in **commitlint**][rules], but with the `function-rules` prefix. The example `commitlint.config.js`, or `commitlint.config.cjs` if the package is an ES module, shows the usage of a function rule.
> **Note** The available rules are the same as in [**commitlint**][commitlint], so it is recommended to disable the [**commitlint**][commitlint] rule when specifying a function rule to avoid undefined behaviour.
```js
module.exports = {
extends: ['@commitlint/config-conventional'],
plugins: ['commitlint-plugin-function-rules'],
rules: {
'header-max-length': [0], // level: disabled
'function-rules/header-max-length': [
2, // level: error
'always',
(parsed) => {
// Allow longer headers for commits with "deps" scope.
if (parsed.scope === 'deps' && parsed.header.length <= 200) {
return [true];
}
return [false, 'deps header must not be longer than 200 characters'];
},
],
},
};
```
## Contributing
Please [create an issue](https://github.com/vidavidorra/commitlint-plugin-function-rules/issues/new/choose) if you have a bug report or feature proposal, or [create a discussion](https://github.com/vidavidorra/commitlint-plugin-function-rules/discussions) if you have a question. If you like this project, please consider giving it a star ⭐
Refer to the [contributing guide](https://github.com/vidavidorra/.github/blob/main/CONTRIBUTING.md) for detailed information about other contributions, like pull requests.
[](https://conventionalcommits.org)
[](https://github.com/xojs/xo)
[](https://github.com/prettier/prettier)
## Security policy
Please refer to the [Security Policy on GitHub](https://github.com/vidavidorra/commitlint-plugin-function-rules/security/) for the security policy.
## License
This project is licensed under the [GPLv3 license](https://www.gnu.org/licenses/gpl.html).
Copyright © 2020-2025 Jeroen de Bruijn
<details><summary>License notice</summary>
<p>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
The full text of the license is available in the [LICENSE](LICENSE.md) file in this repository and [online](https://www.gnu.org/licenses/gpl.html).
</details>
<!-- References -->
[commitlint]: https://commitlint.js.org/
[rules]: https://commitlint.js.org/#/reference-rules