|
| 1 | +[](https://pkg.go.dev/github.com/conventionalcommit/commitlint) |
| 2 | + |
1 | 3 | # commitlint |
2 | 4 |
|
3 | 5 | commitlint checks if your commit messages meets the [conventional commit format](https://www.conventionalcommits.org/en/v1.0.0/) |
4 | 6 |
|
5 | | -[](https://pkg.go.dev/github.com/conventionalcommit/commitlint) |
| 7 | +``` |
| 8 | +<type>[optional scope]: <description> |
6 | 9 |
|
7 | | -#### Table of Contents |
| 10 | +[optional body] |
| 11 | +
|
| 12 | +[optional footer(s)] |
| 13 | +``` |
| 14 | + |
| 15 | +- [Why Use Conventional Commits?](https://www.conventionalcommits.org/en/v1.0.0/#why-use-conventional-commits) |
| 16 | + |
| 17 | +### Table of Contents |
8 | 18 |
|
9 | 19 | - [Installation](#installation) |
10 | 20 | - [Releases](#releases) |
11 | 21 | - [Using go](#using-go) |
12 | | -- [Enable in Git Repo](#enable-in-git-repo) |
| 22 | +- [Setup](#setup) |
| 23 | + - [Manual](#manual) |
13 | 24 | - [Quick Test](#quick-test) |
14 | | -- [Benefits of using conventional commit](#benefits-of-using-conventional-commit) |
15 | | - - [Commit Types](#commit-types) |
16 | | -- [Commands](#commands) |
17 | | - * [Custom config for each repo](#custom-config-for-each-repo) |
18 | | - * [Verify config file](#verify-config-file) |
19 | | -- [Rules](#rules) |
20 | | -- [Library](#library) |
21 | | - - [Config Precedence](#config-precedence) |
22 | | - - [Commit Message Precedence](#commit-message-precedence) |
23 | | -- [Default Config](#default-config) |
| 25 | +- [Usage](#usage) |
| 26 | + - [Commands](#commands) |
| 27 | + - [config](#config) |
| 28 | + - [lint](#lint) |
| 29 | + - [Default Config](#default-config) |
| 30 | + - [Commit Types](#commit-types) |
| 31 | +- [Available Rules](#available-rules) |
| 32 | +- [Available Formatters](#available-formatters) |
| 33 | +- [Extensibility](#extensibility) |
| 34 | +- [FAQ](#faq) |
24 | 35 | - [License](#license) |
25 | 36 |
|
26 | | -### Installation |
| 37 | +## Installation |
27 | 38 |
|
28 | | -#### Releases |
| 39 | +### Releases |
29 | 40 |
|
30 | 41 | Download binary from [releases](https://github.com/conventionalcommit/commitlint/releases) and add it to your `PATH` |
31 | 42 |
|
32 | | -#### Using go |
| 43 | +### Using go |
33 | 44 |
|
34 | 45 | ```bash |
35 | 46 | go install github.com/conventionalcommit/commitlint@latest |
36 | 47 | ``` |
37 | 48 |
|
38 | | -### Enable in Git Repo |
39 | | - |
40 | | -- enable for a single repository, `cd` to repository directory |
41 | | - |
42 | | - ```bash |
43 | | - commitlint init |
44 | | - ``` |
| 49 | +## Setup |
45 | 50 |
|
46 | | -- enable globally for all repositories |
47 | | - |
48 | | - ```bash |
49 | | - commitlint init --global |
50 | | - ``` |
51 | | - |
52 | | -### Quick Test |
| 51 | +- Enable for a single git repository, `cd` to repository directory |
53 | 52 |
|
54 | 53 | ```bash |
55 | | -# invalid commit message |
56 | | -echo "fear: do not fear for commit message" | commitlint lint |
57 | | -# ❌ type-enum: type 'fear' is not allowed, you can use one of [feat fix docs style refactor perf test build ci chore revert merge] |
58 | | - |
59 | | -# valid commit message |
60 | | -echo "feat: good commit message" | commitlint lint |
61 | | -# ✔ commit message |
| 54 | +commitlint init |
62 | 55 | ``` |
63 | 56 |
|
64 | | -### Benefits of using conventional commit |
| 57 | +- Enable globally for all git repositories |
65 | 58 |
|
66 | | -- Conventional Commit format. Read [Full Specification here](https://www.conventionalcommits.org/en/v1.0.0/#specification) |
| 59 | +```bash |
| 60 | +commitlint init --global |
67 | 61 | ``` |
68 | | -<type>[optional scope]: <description> |
69 | 62 |
|
70 | | -[optional body] |
71 | | -
|
72 | | -[optional footer(s)] |
73 | | -``` |
| 63 | +### Manual |
74 | 64 |
|
75 | | -- [Why Use Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#why-use-conventional-commits) |
| 65 | +- run `commitlint hook create` to create `.commitlint/hooks` containing git hooks |
| 66 | +- To enable in single repo |
| 67 | + - run `git config core.hooksPath /path/to/.commitlint/hooks` |
| 68 | +- To enable globally |
| 69 | + - run `git config --global core.hooksPath /path/to/.commitlint/hooks` |
76 | 70 |
|
77 | | -#### Commit Types |
| 71 | +## Quick Test |
78 | 72 |
|
79 | | -Commonly used commit types from [Conventional Commit Types](https://github.com/commitizen/conventional-commit-types) |
| 73 | +- Valid commit message |
80 | 74 |
|
81 | | -| Type | Description | |
82 | | -|:---------|:---------------------------------------------------------------------------------| |
83 | | -| feat | A new feature | |
84 | | -| fix | A bug fix | |
85 | | -| docs | Documentation only changes | |
86 | | -| style | Changes that do not affect the meaning of the code (white-space, formatting etc) | |
87 | | -| refactor | A code change that neither fixes a bug nor adds a feature | |
88 | | -| perf | A code change that improves performance | |
89 | | -| test | Adding missing tests or correcting existing tests | |
90 | | -| build | Changes that affect the build system or external dependencies | |
91 | | -| ci | Changes to our CI configuration files and scripts | |
92 | | -| chore | Other changes that don't modify src or test files | |
93 | | -| revert | Reverts a previous commit | |
94 | | -| merge | Merges a branch | |
| 75 | +```bash |
| 76 | +echo "feat: good commit message" | commitlint lint |
| 77 | +# ✔ commit message |
| 78 | +``` |
95 | 79 |
|
96 | | -### Commands |
| 80 | +- Invalid commit message |
97 | 81 |
|
98 | | -##### Custom config for each repo |
| 82 | +```bash |
| 83 | +echo "fear: do not fear for commit message" | commitlint lint |
| 84 | +# ❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix merge perf refactor revert style test] |
| 85 | +``` |
99 | 86 |
|
100 | | -- run `commitlint create config` in repo root directory |
| 87 | +## Usage |
101 | 88 |
|
102 | | - this will create `commitlint.yaml` in that directory, you can customise the config to your need |
| 89 | +### Commands |
103 | 90 |
|
104 | | -##### Verify config file |
| 91 | +#### config |
105 | 92 |
|
106 | | -- run `commitlint verify` to verify if config is valid or not (according to config precedence) |
| 93 | +- To create config file, run `commitlint config create` this will create `commitlint.yaml` |
107 | 94 |
|
108 | | -- run `commitlint verify --config=/path/to/conf.yaml`to verify given config file |
| 95 | +- To validate config file, run `commitlint config check --config=/path/to/conf.yaml` |
109 | 96 |
|
110 | | -### Rules |
| 97 | +#### lint |
111 | 98 |
|
112 | | -The list of available lint rules |
| 99 | +To lint a message, you can use any one of the following |
| 100 | +- run `commitlint lint --message=file` |
| 101 | +- run `echo "message" | commitlint lint` |
| 102 | +- run `commitlint lint < file` |
113 | 103 |
|
114 | | -| name | argument | flags | description | |
115 | | -| ---------------------- | -------- | ----------------- | -------------------------------------------- | |
116 | | -| header-min-length | int | n/a | checks the min length of header (first line) | |
117 | | -| header-max-length | int | n/a | checks the max length of header (first line) | |
118 | | -| body-max-line-length | int | n/a | checks the max length of each line in body | |
119 | | -| footer-max-line-length | int | n/a | checks the max length of each line in footer | |
120 | | -| type-enum | []string | n/a | restrict type to given list of string | |
121 | | -| scope-enum | []string | allow-empty: bool | restrict scope to given list of string | |
122 | | -| type-min-length | int | n/a | checks the min length of type | |
123 | | -| type-max-length | int | n/a | checks the max length of type | |
124 | | -| scope-min-length | int | n/a | checks the min length of scope | |
125 | | -| scope-max-length | int | n/a | checks the max length of scope | |
126 | | -| description-min-length | int | n/a | checks the min length of description | |
127 | | -| description-max-length | int | n/a | checks the max length of description | |
128 | | -| body-min-length | int | n/a | checks the min length of body | |
129 | | -| body-max-length | int | n/a | checks the max length of body | |
130 | | -| footer-min-length | int | n/a | checks the min length of footer | |
131 | | -| footer-max-length | int | n/a | checks the max length of footer | |
132 | | -| type-charset | string | n/a | restricts type to given charset | |
133 | | -| scope-charset | string | n/a | restricts scope to given charset | |
| 104 | +##### Precedence |
134 | 105 |
|
135 | | -### Library |
| 106 | +`commitlint lint` follows below order for `config` and `message` |
136 | 107 |
|
137 | | -#### Config Precedence |
| 108 | +###### Config |
138 | 109 |
|
139 | 110 | - `commitlint.yaml` config file in current directory |
140 | | -- config file passed with `--config` command-line argument |
| 111 | +- config file passed to `--config` command-line argument |
141 | 112 | - [default config](#default-config) |
142 | 113 |
|
143 | | -#### Commit Message Precedence |
| 114 | +###### Message |
144 | 115 |
|
145 | 116 | - `stdin` pipe stream |
146 | | -- commit message file passed with `--message` command-line argument |
| 117 | +- commit message file passed to `--message` command-line argument |
147 | 118 | - `.git/COMMIT_EDITMSG` in current directory |
148 | 119 |
|
149 | 120 | ### Default Config |
@@ -185,6 +156,83 @@ rules: |
185 | 156 | - merge |
186 | 157 | ``` |
187 | 158 |
|
188 | | -### License |
| 159 | +#### Commit Types |
| 160 | +
|
| 161 | +Commonly used commit types from [Conventional Commit Types](https://github.com/commitizen/conventional-commit-types) |
| 162 | +
|
| 163 | +| Type | Description | |
| 164 | +|:---------|:---------------------------------------------------------------------------------| |
| 165 | +| feat | A new feature | |
| 166 | +| fix | A bug fix | |
| 167 | +| docs | Documentation only changes | |
| 168 | +| style | Changes that do not affect the meaning of the code (white-space, formatting etc) | |
| 169 | +| refactor | A code change that neither fixes a bug nor adds a feature | |
| 170 | +| perf | A code change that improves performance | |
| 171 | +| test | Adding missing tests or correcting existing tests | |
| 172 | +| build | Changes that affect the build system or external dependencies | |
| 173 | +| ci | Changes to our CI configuration files and scripts | |
| 174 | +| chore | Other changes that don't modify src or test files | |
| 175 | +| revert | Reverts a previous commit | |
| 176 | +| merge | Merges a branch | |
| 177 | +
|
| 178 | +## Available Rules |
| 179 | +
|
| 180 | +The list of available lint rules |
| 181 | +
|
| 182 | +| name | argument | flags | description | |
| 183 | +| ---------------------- | -------- | ----------------- | -------------------------------------------- | |
| 184 | +| header-min-length | int | n/a | checks the min length of header (first line) | |
| 185 | +| header-max-length | int | n/a | checks the max length of header (first line) | |
| 186 | +| body-max-line-length | int | n/a | checks the max length of each line in body | |
| 187 | +| footer-max-line-length | int | n/a | checks the max length of each line in footer | |
| 188 | +| type-enum | []string | n/a | restrict type to given list of string | |
| 189 | +| scope-enum | []string | allow-empty: bool | restrict scope to given list of string | |
| 190 | +| type-min-length | int | n/a | checks the min length of type | |
| 191 | +| type-max-length | int | n/a | checks the max length of type | |
| 192 | +| scope-min-length | int | n/a | checks the min length of scope | |
| 193 | +| scope-max-length | int | n/a | checks the max length of scope | |
| 194 | +| description-min-length | int | n/a | checks the min length of description | |
| 195 | +| description-max-length | int | n/a | checks the max length of description | |
| 196 | +| body-min-length | int | n/a | checks the min length of body | |
| 197 | +| body-max-length | int | n/a | checks the max length of body | |
| 198 | +| footer-min-length | int | n/a | checks the min length of footer | |
| 199 | +| footer-max-length | int | n/a | checks the max length of footer | |
| 200 | +| type-charset | string | n/a | restricts type to given charset | |
| 201 | +| scope-charset | string | n/a | restricts scope to given charset | |
| 202 | +
|
| 203 | +
|
| 204 | +## Available Formatters |
| 205 | +
|
| 206 | +- default |
| 207 | +
|
| 208 | +``` |
| 209 | +commitlint |
| 210 | + |
| 211 | +→ input: "fear: do not fear for ..." |
| 212 | + |
| 213 | +Errors: |
| 214 | + ❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix merge perf refactor revert style test] |
| 215 | + |
| 216 | +Total 1 errors, 0 warnings |
| 217 | +``` |
| 218 | + |
| 219 | +- JSON |
| 220 | + |
| 221 | +```json |
| 222 | +{"errors":[{"message":"type 'fear' is not allowed, you can use one of [build chore ci docs feat fix merge perf refactor revert style test]","name":"type-enum"}],"input":"fear: do not fear for commit","status":false,"warnings":[]} |
| 223 | +``` |
| 224 | + |
| 225 | +## Extensibility |
| 226 | + |
| 227 | +## FAQ |
| 228 | + |
| 229 | +- How to have custom config for each repository? |
| 230 | + |
| 231 | + Place `commitlint.yaml` file in repo root directory. linter follows [config precedence](#precedence). |
| 232 | + |
| 233 | + To create a sample config, run `commitlint config create` |
| 234 | + |
| 235 | +## License |
189 | 236 |
|
190 | 237 | All packages are licensed under [MIT License](https://github.com/conventionalcommit/commitlint/tree/master/LICENSE.md) |
| 238 | + |
0 commit comments