Debian Codegraph @

docs/rules.md

raw symbols SCIP
1 # Overview
2
3 The table below shows an overview of all gitlint's built-in rules, with more specific details further down the page.
4
5 Gitlint also has [community **contrib**uted rules](contrib_rules.md) which are not listed here as they're disabled by default.
6
7 In addition, you can also [write your own user-defined rule](user_defined_rules.md) in case you don't find
8 what you're looking for.
9
10
11 | ID | Name | gitlint version | Description |
12 | --- | --------------------------- | --------------- | ------------------------------------------------------------------------------------------- |
13 | T1 | title-max-length | >= 0.1.0 | Title length must be <= 72 chars. |
14 | T2 | title-trailing-whitespace | >= 0.1.0 | Title cannot have trailing whitespace (space or tab) |
15 | T3 | title-trailing-punctuation | >= 0.1.0 | Title cannot have trailing punctuation (?:!.,;) |
16 | T4 | title-hard-tab | >= 0.1.0 | Title cannot contain hard tab characters (\t) |
17 | T5 | title-must-not-contain-word | >= 0.1.0 | Title cannot contain certain words (default: "WIP") |
18 | T6 | title-leading-whitespace | >= 0.4.0 | Title cannot have leading whitespace (space or tab) |
19 | T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: None) |
20 | T8 | title-min-length | >= 0.14.0 | Title length must be >= 5 chars. |
21 | B1 | body-max-line-length | >= 0.1.0 | Lines in the body must be <= 80 chars |
22 | B2 | body-trailing-whitespace | >= 0.1.0 | Body cannot have trailing whitespace (space or tab) |
23 | B3 | body-hard-tab | >= 0.1.0 | Body cannot contain hard tab characters (\t) |
24 | B4 | body-first-line-empty | >= 0.1.0 | First line of the body (second line of commit message) must be empty |
25 | B5 | body-min-length | >= 0.4.0 | Body length must be at least 20 characters |
26 | B6 | body-is-missing | >= 0.4.0 | Body message must be specified |
27 | B7 | body-changed-file-mention | >= 0.4.0 | Body must contain references to certain files if those files are changed in the last commit |
28 | B8 | body-match-regex | >= 0.14.0 | Body must match a given regex (default: None) |
29 | M1 | author-valid-email | >= 0.9.0 | Author email address must be a valid email address |
30 | I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title |
31 | I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body |
32 | I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex |
33 | I4 | ignore-by-author-name | >= 0.16.0 | Ignore a commit based on matching its author name |
34
35
36
37 ## T1: title-max-length
38
39 | ID | Name | gitlint version | Description |
40 | --- | ---------------- | --------------- | ------------------------------------ |
41 | T1 | title-max-length | >= 0.1 | Title length must be <= 72 chars. |
42
43 ### Options
44
45 | Name | gitlint version | Default | Description |
46 | ----------- | --------------- | ------- | ---------------------------- |
47 | line-length | >= 0.2 | 72 | Maximum allowed title length |
48
49 ### Examples
50
51 #### .gitlint
52
53 ```ini
54 # Titles should be max 72 chars
55 [title-max-length]
56 line-length=72
57
58 # It's the 21st century, titles can be 120 chars long
59 [title-max-length]
60 line-length=120
61 ```
62 ------------------------------------------------------------------------------------------------------------------------
63
64 ## T2: title-trailing-whitespace
65
66 | ID | Name | gitlint version | Description |
67 | --- | ------------------------- | --------------- | ---------------------------------------------------- |
68 | T2 | title-trailing-whitespace | >= 0.1 | Title cannot have trailing whitespace (space or tab) |
69
70 ------------------------------------------------------------------------------------------------------------------------
71
72 ## T3: title-trailing-punctuation
73
74 | ID | Name | gitlint version | Description |
75 | --- | -------------------------- | --------------- | ----------------------------------------------- |
76 | T3 | title-trailing-punctuation | >= 0.1 | Title cannot have trailing punctuation (?:!.,;) |
77
78 ------------------------------------------------------------------------------------------------------------------------
79
80 ## T4: title-hard-tab
81
82 | ID | Name | gitlint version | Description |
83 | --- | -------------- | --------------- | --------------------------------------------- |
84 | T4 | title-hard-tab | >= 0.1 | Title cannot contain hard tab characters (\t) |
85
86 ------------------------------------------------------------------------------------------------------------------------
87
88 ## T5: title-must-not-contain-word
89
90 | ID | Name | gitlint version | Description |
91 | --- | --------------------------- | --------------- | --------------------------------------------------- |
92 | T5 | title-must-not-contain-word | >= 0.1 | Title cannot contain certain words (default: "WIP") |
93
94 ### Options
95
96 | Name | gitlint version | Default | Description |
97 | ----- | --------------- | ------- | ------------------------------------------------------------------------------------------------ |
98 | words | >= 0.3 | WIP | Comma-separated list of words that should not be used in the title. Matching is case insensitive |
99
100 ### Examples
101
102 #### .gitlint
103
104 ```ini
105 # Ensure the title doesn't contain swear words
106 [title-must-not-contain-word]
107 words=crap,darn,damn
108 ```
109 ------------------------------------------------------------------------------------------------------------------------
110
111 ## T6: title-leading-whitespace
112
113 | ID | Name | gitlint version | Description |
114 | --- | ------------------------ | --------------- | --------------------------------------------------- |
115 | T6 | title-leading-whitespace | >= 0.4 | Title cannot have leading whitespace (space or tab) |
116
117 ------------------------------------------------------------------------------------------------------------------------
118
119 ## T7: title-match-regex
120
121 | ID | Name | gitlint version | Description |
122 | --- | ----------------- | --------------- | -------------------------------------------- |
123 | T7 | title-match-regex | >= 0.5 | Title must match a given regex (default: .*) |
124
125
126 ### Options
127
128 | Name | gitlint version | Default | Description |
129 | ----- | --------------- | ------- | ------------------------------------------------------------------------------------ |
130 | regex | >= 0.5 | .* | [Python regex](https://docs.python.org/library/re.html) that the title should match. |
131
132 ### Examples
133
134 #### .gitlint
135
136 ```ini
137 # Ensure every title starts with a user-story like US123
138 [title-match-regex]
139 regex=^US[1-9][0-9]*
140 ```
141 ------------------------------------------------------------------------------------------------------------------------
142
143 ## T8: title-min-length ##
144
145 | ID | Name | gitlint version | Description |
146 | --- | ---------------- | --------------- | ----------------------------------- |
147 | T8 | title-min-length | >= 0.14.0 | Title length must be >= 5 chars. |
148
149
150 ### Options
151
152 | Name | gitlint version | Default | Description |
153 | ---------- | --------------- | ------- | ----------------------------- |
154 | min-length | >= 0.14.0 | 5 | Minimum required title length |
155
156 ### Examples
157
158 #### .gitlint
159
160 ```ini
161 # Titles should be min 3 chars
162 [title-min-length]
163 min-length=3
164 ```
165 ------------------------------------------------------------------------------------------------------------------------
166
167 ## B1: body-max-line-length
168
169 | ID | Name | gitlint version | Description |
170 | --- | -------------------- | --------------- | ---------------------------------------- |
171 | B1 | body-max-line-length | >= 0.1 | Lines in the body must be <= 80 chars |
172
173 ### Options
174
175 | Name | gitlint version | Default | Description |
176 | ----------- | --------------- | ------- | ------------------------------------------------------ |
177 | line-length | >= 0.2 | 80 | Maximum allowed line length in the commit message body |
178
179 ### Examples
180
181 #### .gitlint
182
183 ```ini
184 # It's the 21st century, lines can be 120 chars long
185 [body-max-line-length]
186 line-length=120
187
188 # Your tool prefers 72
189 [body-max-line-length]
190 line-length=72
191 ```
192 ------------------------------------------------------------------------------------------------------------------------
193
194 ## B2: body-trailing-whitespace
195
196 | ID | Name | gitlint version | Description |
197 | --- | ------------------------ | --------------- | --------------------------------------------------- |
198 | B2 | body-trailing-whitespace | >= 0.1 | Body cannot have trailing whitespace (space or tab) |
199
200 ------------------------------------------------------------------------------------------------------------------------
201
202 ## B3: body-hard-tab
203
204 | ID | Name | gitlint version | Description |
205 | --- | ------------- | --------------- | -------------------------------------------- |
206 | B3 | body-hard-tab | >= 0.1 | Body cannot contain hard tab characters (\t) |
207
208 ------------------------------------------------------------------------------------------------------------------------
209
210 ## B4: body-first-line-empty
211
212 | ID | Name | gitlint version | Description |
213 | --- | --------------------- | --------------- | -------------------------------------------------------------------- |
214 | B4 | body-first-line-empty | >= 0.1 | First line of the body (second line of commit message) must be empty |
215
216 ------------------------------------------------------------------------------------------------------------------------
217
218 ## B5: body-min-length
219
220 | ID | Name | gitlint version | Description |
221 | --- | --------------- | --------------- | ------------------------------------------------------------------------------------------------------------ |
222 | B5 | body-min-length | >= 0.4 | Body length must be at least 20 characters. In versions >= 0.8.0, gitlint will not count newline characters. |
223
224 ### Options ###
225
226 | Name | gitlint version | Default | Description |
227 | ---------- | --------------- | ------- | --------------------------------------------- |
228 | min-length | >= 0.4 | 20 | Minimum number of required characters in body |
229
230 ### Examples
231
232 #### .gitlint
233
234 ```ini
235 # You want *something* in every commit body, but doesn't have to be as long as 20 chars.
236 [body-min-length]
237 min-length=5
238
239 # You want a more elaborate message in every commit body
240 [body-min-length]
241 min-length=100
242 ```
243 ------------------------------------------------------------------------------------------------------------------------
244
245 ## B6: body-is-missing
246
247 | ID | Name | gitlint version | Description |
248 | --- | --------------- | --------------- | ------------------------------ |
249 | B6 | body-is-missing | >= 0.4 | Body message must be specified |
250
251
252 ### Options
253
254 | Name | gitlint version | Default | Description |
255 | -------------------- | --------------- | ------- | ------------------------------------------------------------------------------------- |
256 | ignore-merge-commits | >= 0.4 | true | Whether this rule should be ignored during merge commits. Allowed values: true,false. |
257
258 ------------------------------------------------------------------------------------------------------------------------
259
260 ## B7: body-changed-file-mention
261
262 | ID | Name | gitlint version | Description |
263 | --- | ------------------------- | --------------- | ------------------------------------------------------------------------------------------- |
264 | B7 | body-changed-file-mention | >= 0.4 | Body must contain references to certain files if those files are changed in the last commit |
265
266 ### Options
267
268 | Name | gitlint version | Default | Description |
269 | ----- | --------------- | ------- | -------------------------------------------------------------------------------------------------------------- |
270 | files | >= 0.4 | (empty) | Comma-separated list of files that need to an explicit mention in the commit message in case they are changed. |
271
272 ### Examples
273
274 #### .gitlint
275
276 ```ini
277 # Prevent that certain sensitive files are committed by mistake by forcing
278 # users to mention them explicitly if they're deliberately changing them
279 [body-changed-file-mention]
280 files=generated.xml,secrets.txt,private-key.pem
281 ```
282 ------------------------------------------------------------------------------------------------------------------------
283
284 ## B8: body-match-regex
285
286 | ID | Name | gitlint version | Description |
287 | --- | ---------------- | --------------- | ----------------------------- |
288 | B8 | body-match-regex | >= 0.14 | Body must match a given regex |
289
290 ### Options
291
292 | Name | gitlint version | Default | Description |
293 | ----- | --------------- | ------- | ----------------------------------------------------------------------------------- |
294 | regex | >= 0.14 | None | [Python regex](https://docs.python.org/library/re.html) that the body should match. |
295
296 ### Examples
297
298 #### .gitlint
299
300 ```ini
301 # Ensure the body ends with Reviewed-By: <some value>
302 [body-match-regex]
303 regex=Reviewed-By:(.*)$
304
305 # Ensure body contains the word "Foo" somewhere
306 [body-match-regex]
307 regex=(*.)Foo(.*)
308 ```
309 ------------------------------------------------------------------------------------------------------------------------
310
311 ## M1: author-valid-email
312
313 | ID | Name | gitlint version | Description |
314 | --- | ------------------ | --------------- | -------------------------------------------------- |
315 | M1 | author-valid-email | >= 0.8.3 | Author email address must be a valid email address |
316
317 !!! note
318 Email addresses are [notoriously hard to validate and the official email valid spec is often too loose for any real world application](http://stackoverflow.com/a/201378/381010).
319 Gitlint by default takes a pragmatic approach and requires users to enter email addresses that contain a name, domain and tld and has no spaces.
320
321
322
323 ### Options
324
325 | Name | gitlint version | Default | Description |
326 | ----- | --------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------- |
327 | regex | >= 0.9.0 | `[^@ ]+@[^@ ]+\.[^@ ]+` | [Python regex](https://docs.python.org/library/re.html) the commit author email address is matched against |
328
329
330 ### Examples
331
332 #### .gitlint
333
334 ```ini
335 # Only allow email addresses from a foo.com domain
336 [author-valid-email]
337 regex=[^@][email protected]
338 ```
339 ------------------------------------------------------------------------------------------------------------------------
340
341 ## I1: ignore-by-title
342
343 | ID | Name | gitlint version | Description |
344 | --- | --------------- | --------------- | -------------------------------------------- |
345 | I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title. |
346
347
348 ### Options
349
350 | Name | gitlint version | Default | Description |
351 | ------ | --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
352 | regex | >= 0.10.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against commit title. On match, the commit will be ignored. |
353 | ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. |
354
355 ### Examples
356
357 #### .gitlint
358
359 ```ini
360 # Match commit titles starting with Release
361 # For those commits, ignore title-max-length and body-min-length rules
362 [ignore-by-title]
363 regex=^Release(.*)
364 ignore=title-max-length,body-min-length
365 # ignore all rules by setting ignore to 'all'
366 # ignore=all
367 ```
368 ------------------------------------------------------------------------------------------------------------------------
369
370 ## I2: ignore-by-body
371
372 | ID | Name | gitlint version | Description |
373 | --- | -------------- | --------------- | ------------------------------------------- |
374 | I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body. |
375
376
377 ### Options
378
379 | Name | gitlint version | Default | Description |
380 | ------ | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------- |
381 | regex | >= 0.10.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against each line of the body. On match, the commit will be ignored. |
382 | ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. |
383
384 ### Examples
385
386 #### .gitlint
387
388 ```ini
389 # Ignore all commits with a commit message body with a line that contains 'release'
390 [ignore-by-body]
391 regex=(.*)release(.*)
392 ignore=all
393
394 # For matching commits, only ignore rules T1, body-min-length, B6.
395 # You can use both names as well as ids to refer to other rules.
396 [ignore-by-body]
397 regex=(.*)release(.*)
398 ignore=T1,body-min-length,B6
399 ```
400 ------------------------------------------------------------------------------------------------------------------------
401
402 ## I3: ignore-body-lines
403
404 | ID | Name | gitlint version | Description |
405 | --- | ----------------- | --------------- | --------------------------------------------------------- |
406 | I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex. |
407
408
409 ### Options
410
411 | Name | gitlint version | Default | Description |
412 | ----- | --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
413 | regex | >= 0.14.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against each line of the body. On match, that line will be ignored by gitlint (the rest of the body will still be linted). |
414
415 ### Examples
416
417 #### .gitlint
418
419 ```ini
420 # Ignore all lines that start with 'Co-Authored-By'
421 [ignore-body-lines]
422 regex=^Co-Authored-By
423
424 # Ignore lines that start with 'Co-Authored-By' or with 'Signed-off-by'
425 [ignore-body-lines]
426 regex=(^Co-Authored-By)|(^Signed-off-by)
427
428 # Ignore lines that contain 'foobar'
429 [ignore-body-lines]
430 regex=(.*)foobar(.*)
431 ```
432 ------------------------------------------------------------------------------------------------------------------------
433
434 ## I4: ignore-by-author-name
435
436 | ID | Name | gitlint version | Description |
437 | --- | --------------------- | --------------- | -------------------------------------------------- |
438 | I4 | ignore-by-author-name | >= 0.16.0 | Ignore a commit based on matching its author name. |
439
440 ### Options
441
442 | Name | gitlint version | Default | Description |
443 | ------ | --------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- |
444 | regex | >= 0.16.0 | None | [Python regex](https://docs.python.org/library/re.html) to match against the commit author name. On match, the commit will be ignored. |
445 | ignore | >= 0.16.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched. |
446
447 ### Examples
448
449 #### .gitlint
450
451 ```ini
452 # Ignore all commits authored by dependabot
453 [ignore-by-author-name]
454 regex=dependabot
455
456 # For commits made by anyone with "[bot]" in their name, ignore
457 # rules T1, body-min-length and B6
458 [ignore-by-author-name]
459 regex=(.*)\[bot\](.*)
460 ignore=T1,body-min-length,B6
461 ```