| 1 | # Using Contrib Rules |
| 2 | |
| 3 | _Introduced in gitlint v0.12.0_ |
| 4 | |
| 5 | Contrib rules are community-**contrib**uted rules that are disabled by default, but can be enabled through configuration. |
| 6 | |
| 7 | Contrib rules are meant to augment default gitlint behavior by providing users with rules for common use-cases without |
| 8 | forcing these rules on all gitlint users. This also means that users don't have to |
| 9 | re-implement these commonly used rules themselves as [user-defined](user_defined_rules.md) rules. |
| 10 | |
| 11 | To enable certain contrib rules, you can use the `--contrib` flag. |
| 12 | ```sh |
| 13 | $ cat examples/commit-message-1 | gitlint --contrib contrib-title-conventional-commits,CC1 |
| 14 | 1: CC1 Body does not contain a 'Signed-off-by' line |
| 15 | 1: CL1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test: "WIP: This is the title of a commit message." |
| 16 | |
| 17 | # These are the default violations |
| 18 | 1: T3 Title has trailing punctuation (.): "WIP: This is the title of a commit message." |
| 19 | 1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: This is the title of a commit message." |
| 20 | 2: B4 Second line is not empty: "The second line should typically be empty" |
| 21 | 3: B1 Line exceeds max length (123>80): "Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120." |
| 22 | ``` |
| 23 | |
| 24 | Same thing using a `.gitlint` file: |
| 25 | |
| 26 | ```ini |
| 27 | [general] |
| 28 | # You HAVE to add the rule here to enable it, only configuring (such as below) |
| 29 | # does NOT enable it. |
| 30 | contrib=contrib-title-conventional-commits,CC1 |
| 31 | |
| 32 | |
| 33 | [contrib-title-conventional-commits] |
| 34 | # Specify allowed commit types. For details see: https://www.conventionalcommits.org/ |
| 35 | types = bugfix,user-story,epic |
| 36 | ``` |
| 37 | |
| 38 | You can also configure contrib rules using [any of the other ways to configure gitlint](configuration.md). |
| 39 | |
| 40 | ## Available Contrib Rules |
| 41 | |
| 42 | ID | Name | gitlint version | Description |
| 43 | ------|-------------------------------------|------------------ |------------------------------------------- |
| 44 | CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [Conventional Commits](https://www.conventionalcommits.org/) commit message style on the title. |
| 45 | CC1 | contrib-body-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-off-by` line. |
| 46 | CC2 | contrib-disallow-cleanup-commits | >= 0.18.0 | Commit title must not contain `fixup!`, `squash!`, `amend!`. |
| 47 | CC3 | contrib-allowed-authors | >= 0.18.0 | Enforce that only authors listed in the `AUTHORS` file are allowed to commit. |
| 48 | |
| 49 | ## CT1: contrib-title-conventional-commits ## |
| 50 | |
| 51 | ID | Name | gitlint version | Description |
| 52 | ------|---------------------------------------|--------------------|------------------------------------------- |
| 53 | CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [Conventional Commits](https://www.conventionalcommits.org/) commit message style on the title. |
| 54 | |
| 55 | ### Options ### |
| 56 | |
| 57 | Name | gitlint version | Default | Description |
| 58 | ---------------|--------------------|--------------|---------------------------------- |
| 59 | types | >= 0.12.0 | `fix,feat,chore,docs,style,refactor,perf,test,revert,ci,build` | Comma separated list of allowed commit types. |
| 60 | |
| 61 | |
| 62 | ## CC1: contrib-body-requires-signed-off-by ## |
| 63 | |
| 64 | ID | Name | gitlint version | Description |
| 65 | ------|---------------------------------------|--------------------|------------------------------------------- |
| 66 | CC1 | contrib-body-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-off-by` line. This means, a line that starts with the `Signed-off-by` keyword. |
| 67 | |
| 68 | |
| 69 | ## CC2: contrib-disallow-cleanup-commits ## |
| 70 | |
| 71 | ID | Name | gitlint version | Description |
| 72 | ------|----------------------------------|--------------------|------------------------------------------- |
| 73 | CC2 | contrib-disallow-cleanup-commits | >= 0.18.0 | Commit title must not contain `fixup!`, `squash!` or `amend!`. This means `git commit --fixup` and `git commit --squash` commits are not allowed. |
| 74 | |
| 75 | ## CC3: contrib-allowed-authors ## |
| 76 | |
| 77 | ID | Name | gitlint version | Description |
| 78 | ------|----------------------------------|--------------------|------------------------------------------- |
| 79 | CC3 | contrib-allowed-authors | >= 0.18.0 | The commit author must be listed in an `AUTHORS` file to be allowed to commit. Possible file names are also `AUTHORS.txt` and `AUTHORS.md`. |
| 80 | |
| 81 | ## Contributing Contrib rules |
| 82 | |
| 83 | We'd love for you to contribute new Contrib rules to gitlint or improve existing ones! Please visit the [Contributing](contributing.md) page on how to get started. |