Skip to content

Commit b7ac835

Browse files
committed
docs: add dedicated configuration docs
1 parent faf5d79 commit b7ac835

File tree

4 files changed

+149
-7
lines changed

4 files changed

+149
-7
lines changed

docs/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ commitlint --from=HEAD~1
6161
* **Guides** - Common use cases explained in a step-by-step pace
6262
* **Concepts** - Overarching topics important to unterstand the use of `commitlint`
6363
* **Reference** - Mostly technical documentation
64-
* **Changelog**
6564

6665

6766
[0]: https://img.shields.io/badge/stability-stable-green.svg?style=flat-square

docs/_sidebar.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010

1111
* **Reference**
1212
* [CLI](reference-cli.md)
13+
* [Configuration](reference-configuration.md)
1314
* [Rules](reference-rules.md)
1415
* [API](reference-api.md)

docs/reference-cli.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ npm install --save-dev @commitlint/cli
1313
commitlint - Lint commit messages
1414

1515
[input] reads from stdin if --edit, --from, --to are omitted
16-
--color,-c toggle formatted output, defaults to: true
17-
--edit,-e read last commit message found in ./git/COMMIT_EDITMSG
18-
--extends,-x array of shareable configurations to extend
19-
--from,-f lower end of the commit range to lint; applies if edit=false
20-
--to,-t upper end of the commit range to lint; applies if edit=false
21-
--quiet,-q toggle console output
16+
--color, -c toggle formatted output, defaults to: true
17+
--edit, -e read last commit message found in ./git/COMMIT_EDITMSG
18+
--extends, -x array of resolvable ids pointing to shareable configurations to extend
19+
--from, -f lower end of the commit range to lint; applies if edit=false
20+
--to, -t upper end of the commit range to lint; applies if edit=false
21+
--quiet, -q toggle console output
22+
--parser-preset, -p resolvable id to load and pass to conventional-commits-parser
2223
```

docs/reference-configuration.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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

Comments
 (0)