UNPKG

4.12 kBMarkdownView Raw
1> Lint commit messages against your conventional-changelog ruleset and preset
2
3# conventional-changelog-lint
4Lint your commit messages against defined rulesets. ` conventional-changelog-lint` plays nice with `conventional-changelog` and takes cues from `eslint`, e.g. shareable configurations.
5
6## Installation
7Fetch it with `npm`
8```shell
9npm install --save-dev conventional-changelog-lint
10```
11
12## Usage
13`conventional-changelog-lint` provides a command line and node interface.
14### CLI
15The command line interface reads `.conventional-changelog-lintrc` resolves `extends` configurations.
16```shell
17❯ conventional-changelog-lint --help
18 conventional-changelog-lint@0.1.0 - Lint commit messages against a conventional-changelog preset and ruleset
19
20 [input] reads from stdin if --edit, --from, --to are omitted
21 --color,-c toggle formatted output, defaults to: true
22 --edit,-e read last commit message found in ./git/COMMIT_EDITMSG
23 --extends,-x array of shareable configurations to extend
24 --from,-f lower end of the commit range to lint; applies if edit=false
25 --preset,-p conventional-changelog-preset to use for commit message parsing, defaults to: angular
26 --to,-t upper end of the commit range to lint; applies if edit=false
27 --quiet,-q toggle console output
28
29```
30
31#### Recipes
32* As a git `commitmsg` hook with husky
33 ```json
34 {
35 "scripts": {
36 "commitmsg": "conventional-changelog-lint -e"
37 }
38 }
39 ```
40* As part of `npm test`
41```json
42 {
43 "scripts": {
44 "test": "conventional-changelog --from=HEAD~1"
45 }
46 }
47```
48
49### API
50The programming interface does not read configuration by default, it has to be provided as second parameter.
51```js
52import lint from 'conventional-changelog-lint';
53const report = lint(
54 'docs: add node api interface usage',
55 {
56 preset: {},
57 configuration: {}
58 }
59);
60```
61
62To achieve the same behavior as with the command line interface you can use the provided utility functions:
63```js
64import lint from 'conventional-changelog-lint';
65import {
66 getPreset,
67 getConfiguration
68} from 'conventional-changelog-lint';
69
70const report = lint(
71 'docs: add node api interface usage',
72 {
73 preset: await getPreset('angular'),
74 configuration: await readConfiguration('conventional-changelog-lint')
75 }
76);
77```
78
79## Configuration
80`conventional-changelog-lint` allows detailed configuration via `.conventional-changelog-lintrc` and shareable configuration. By default it will use the [angular](https://github.com/marionebl/conventional-changelog-lint-config-angular#rules) shareable config. See the documentation there for default rules.
81
82### extends
83```js
84{
85 "extends": ["angular"]
86}
87```
88Array of shareable configurations to extend. Configurations are resolved as `conventional-changelog-lint-config-${name}` and have to be installed. See [npm search](https://www.npmjs.com/search?q=conventional-changelog-lint-config) for available shareable configurations.
89
90---
91⇨ See [shareable-config](./documentation/shareable-config.md) for details
92
93### preset
94```js
95{
96 "preset": "angular"
97}
98```
99`conventional-changelog` preset name to use for parsing of commit messages.
100
101---
102⇨ See [conventional-changelog](https://github.com/ajoslin/conventional-changelog#preset) for details
103
104### rules
105```js
106{
107 "rules": {
108 "body-leading-blank": [1, "always"],
109 "header-max-length": [1, "always", 72],
110 "subject-full-stop": [1, "never", "."]
111 }
112}
113```
114Rules applicable to the linted commit messages. By default all rules are disabled via a level of 0. They can be enabled by shareable configuration, such as the [angular config](/marionebl/conventional-changelog-lint-config-angular), which is loaded by default.
115
116---
117⇨ See [rules](./documentation/rules.md) for details
118
119### wildcards
120```js
121wildcards: {
122 merge: [
123 '/^(Merge pull request)|(Merge (.*?) into (.*?)$)/'
124 ],
125 release: [
126 '/^\\d.\\d.\\d$/'
127 ],
128 revert: [
129 '/^revert: (.*)/'
130 ]
131}
132```
133Patterns to exclude from linting
134
135---
136Copyright 2016 by [Mario Nebl](https://github.com/marionebl) and [contributors](./graphs/contributors). Released under the [MIT license]('./license.md').