summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docs/configuration.md296
-rw-r--r--docs/contrib_rules.md12
-rw-r--r--docs/contributing.md55
-rw-r--r--docs/extra.js5
-rw-r--r--docs/index.md176
-rw-r--r--docs/rules.md244
-rw-r--r--docs/user_defined_rules.md264
7 files changed, 714 insertions, 338 deletions
diff --git a/docs/configuration.md b/docs/configuration.md
index 641b361..78224c1 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -1,21 +1,21 @@
# Configuration
Gitlint can be configured through different means.
-# Config files #
-You can modify gitlint's behavior by adding a ```.gitlint``` file to your git repository.
+## The .gitlint file
+You can modify gitlint's behavior by adding a `.gitlint` file to your git repository.
-Generate a default ```.gitlint``` config file by running:
-```bash
+Generate a default `.gitlint` config file by running:
+```sh
gitlint generate-config
```
You can also use a different config file like so:
-```bash
+```sh
gitlint --config myconfigfile.ini
```
-The block below shows a sample ```.gitlint``` file. Details about rule config options can be found on the
-[Rules](rules.md) page, details about the ```[general]``` section can be found in the
+The block below shows a sample `.gitlint` file. Details about rule config options can be found on the
+[Rules](rules.md) page, details about the `[general]` section can be found in the
[General Configuration](configuration.md#general-configuration) section of this page.
```ini
@@ -25,7 +25,7 @@ The block below shows a sample ```.gitlint``` file. Details about rule config op
# one rule and each key in it is an option for that specific rule.
#
# Rules and sections can be referenced by their full name or by id. For example
-# section "[body-max-line-length]" could be written as "[B1]". Full section names are
+# section "[body-max-line-length]" could also be written as "[B1]". Full section names are
# used in here for clarity.
# Rule reference documentation: http://jorisroovers.github.io/gitlint/rules/
#
@@ -68,6 +68,11 @@ extra-path=examples/
[title-max-length]
line-length=80
+# Conversely, you can also enforce minimal length of a title with the
+# "title-min-length" rule:
+[title-min-length]
+min-length=5
+
[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
@@ -99,10 +104,15 @@ ignore-merge-commits=false
# it in the commit message.
files=gitlint/rules.py,README.md
+[body-match-regex]
+# python-style regex that the commit-msg body must match.
+# E.g. body must end in My-Commit-Tag: foo
+regex=My-Commit-Tag: foo$
+
[author-valid-email]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit author email address should be matched to
-# For example, use the following regex if you only want to allow email addresses from foo.com
+# E.g.: For example, use the following regex if you only want to allow email addresses from foo.com
regex=[^@]+@foo.com
[ignore-by-title]
@@ -123,6 +133,11 @@ ignore=T1,body-min-length
# Use 'all' to ignore all rules
ignore=T1,body-min-length
+[ignore-body-lines]
+# Ignore certain lines in a commit body that match a regex.
+# E.g. Ignore all lines that start with 'Co-Authored-By'
+regex=^Co-Authored-By
+
# This is a contrib rule - a community contributed rule. These are disabled by default.
# You need to explicitly enable them one-by-one by adding them to the "contrib" option
# under [general] section above.
@@ -131,20 +146,20 @@ ignore=T1,body-min-length
types = bugfix,user-story,epic
```
-# Commandline config #
+## Commandline config
-You can also use one or more ```-c``` flags like so:
+You can also use one or more `-c` flags like so:
```
$ gitlint -c general.verbosity=2 -c title-max-length.line-length=80 -c B1.line-length=100
```
-The generic config flag format is ```-c <rule>.<option>=<value>``` and supports all the same rules and options which
-you can also use in a ```.gitlint``` config file.
+The generic config flag format is `-c <rule>.<option>=<value>` and supports all the same rules and options which
+you can also use in a `.gitlint` config file.
-# Commit specific config #
+## Commit specific config
You can also configure gitlint by adding specific lines to your commit message.
-For now, we only support ignoring commits by adding ```gitlint-ignore: all``` to the commit
+For now, we only support ignoring commits by adding `gitlint-ignore: all` to the commit
message like so:
```
@@ -154,7 +169,7 @@ I want gitlint to ignore this entire commit message.
gitlint-ignore: all
```
-```gitlint-ignore: all``` can occur on any line, as long as it is at the start of the line.
+`gitlint-ignore: all` can occur on any line, as long as it is at the start of the line.
You can also specify specific rules to be ignored as follows:
```
@@ -166,44 +181,46 @@ gitlint-ignore: T1, body-hard-tab
-# Configuration precedence #
+## Configuration precedence
gitlint configuration is applied in the following order of precedence:
-1. Commit specific config (e.g.: ```gitlint-ignore: all``` in the commit message)
+1. Commit specific config (e.g.: `gitlint-ignore: all` in the commit message)
2. Configuration Rules (e.g.: [ignore-by-title](/rules/#i1-ignore-by-title))
-3. Commandline convenience flags (e.g.: ```-vv```, ```--silent```, ```--ignore```)
-4. Commandline configuration flags (e.g.: ```-c title-max-length=123```)
-5. Configuration file (local ```.gitlint``` file, or file specified using ```-C```/```--config```)
-6. Default gitlint config
+3. Commandline convenience flags (e.g.: `-vv`, `--silent`, `--ignore`)
+4. Environment variables (e.g.: `GITLINT_VERBOSITY=3`)
+5. Commandline configuration flags (e.g.: `-c title-max-length=123`)
+6. Configuration file (local `.gitlint` file, or file specified using `-C`/`--config`)
+7. Default gitlint config
-# General Options
+## General Options
Below we outline all configuration options that modify gitlint's overall behavior. These options can be specified
-using commandline flags or in ```[general]``` section in a ```.gitlint``` configuration file.
+using commandline flags or in `[general]` section in a `.gitlint` configuration file.
-## silent
+### silent
Enable silent mode (no output). Use [exit](index.md#exit-codes) code to determine result.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- false | >= 0.1.0 | ```--silent```
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+`False` | >= 0.1.0 | `--silent` | `GITLINT_SILENT`
-### Examples
+#### Examples
```sh
# CLI
gitlint --silent
+GITLINT_SILENT=1 gitlint # using env variable
```
-## verbosity
+### verbosity
Amount of output gitlint will show when printing errors.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- 3 | >= 0.1.0 | `-v`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+3 | >= 0.1.0 | `-v` | `GITLINT_VERBOSITY`
-### Examples
+#### Examples
```sh
# CLI
gitlint -vvv # default (level 3)
@@ -212,221 +229,230 @@ gitlint -v # even less (level 1)
gitlint --silent # no output (level 0)
gitlint -c general.verbosity=1 # Set specific level
gitlint -c general.verbosity=0 # Same as --silent
+GITLINT_VERBOSITY=2 gitlint # using env variable
```
```ini
-.gitlint
+# .gitlint
[general]
verbosity=2
```
-## ignore-merge-commits
+### ignore
-Whether or not to ignore merge commits.
+Comma separated list of rules to ignore (by name or id).
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- true | >= 0.7.0 | Not Available
+Default value | gitlint version | commandline flag | environment variable
+---------------------------|------------------|-------------------|-----------------------
+ [] (=empty list) | >= 0.1.0 | `--ignore` | `GITLINT_IGNORE`
-### Examples
+#### Examples
```sh
# CLI
-gitlint -c general.ignore-merge-commits=false
+gitlint --ignore=body-min-length # ignore single rule
+gitlint --ignore=T1,body-min-length # ignore multiple rule
+gitlint -c general.ignore=T1,body-min-length # different way of doing the same
+GITLINT_IGNORE=T1,body-min-length gitlint # using env variable
```
```ini
#.gitlint
[general]
-ignore-merge-commits=false
+ignore=T1,body-min-length
```
-## ignore-revert-commits
+### debug
-Whether or not to ignore revert commits.
+Enable debugging output.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- true | >= 0.13.0 | Not Available
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ false | >= 0.7.1 | `--debug` | `GITLINT_DEBUG`
-### Examples
+#### Examples
```sh
# CLI
-gitlint -c general.ignore-revert-commits=false
-```
-```ini
-#.gitlint
-[general]
-ignore-revert-commits=false
+gitlint --debug
+GITLINT_DEBUG=1 gitlint # using env variable
+# --debug is special, the following does NOT work
+# gitlint -c general.debug=true
```
-## ignore-fixup-commits
+### target
-Whether or not to ignore [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits.
+Target git repository gitlint should be linting against.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- true | >= 0.9.0 | Not Available
+Default value | gitlint version | commandline flag | environment variable
+---------------------------|------------------|-------------------|-----------------------
+(empty) | >= 0.8.0 | `--target` | `GITLINT_TARGET`
-### Examples
+#### Examples
```sh
# CLI
-gitlint -c general.ignore-fixup-commits=false
+gitlint --target=/home/joe/myrepo/
+gitlint -c general.target=/home/joe/myrepo/ # different way of doing the same
+GITLINT_TARGET=/home/joe/myrepo/ gitlint # using env variable
```
```ini
#.gitlint
[general]
-ignore-fixup-commits=false
+target=/home/joe/myrepo/
```
-## ignore-squash-commits
+### extra-path
-Whether or not to ignore [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) commits.
+Path where gitlint looks for [user-defined rules](user_defined_rules.md).
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- true | >= 0.9.0 | Not Available
+Default value | gitlint version | commandline flag | environment variable
+---------------------------|------------------|-------------------|-----------------------
+ (empty) | >= 0.8.0 | `--extra-path` | `GITLINT_EXTRA_PATH`
-### Examples
+#### Examples
```sh
# CLI
-gitlint -c general.ignore-squash-commits=false
+gitlint --extra-path=/home/joe/rules/
+gitlint -c general.extra-path=/home/joe/rules/ # different way of doing the same
+GITLINT_EXTRA_PATH=/home/joe/rules/ gitlint # using env variable
```
```ini
#.gitlint
[general]
-ignore-squash-commits=false
+extra-path=/home/joe/rules/
```
-## ignore
+### contrib
-Comma separated list of rules to ignore (by name or id).
+Comma-separated list of [Contrib rules](contrib_rules) to enable (by name or id).
-Default value | gitlint version | commandline flag
----------------------------|------------------|-------------------
- [] (=empty list) | >= 0.1.0 | `--ignore`
+Default value | gitlint version | commandline flag | environment variable
+---------------------------|------------------|-------------------|-----------------------
+ (empty) | >= 0.12.0 | `--contrib` | `GITLINT_CONTRIB`
-### Examples
+#### Examples
```sh
# CLI
-gitlint --ignore=body-min-length # ignore single rule
-gitlint --ignore=T1,body-min-length # ignore multiple rule
-gitlint -c general.ignore=T1,body-min-length # different way of doing the same
+gitlint --contrib=contrib-title-conventional-commits,CC1
+gitlint -c general.contrib=contrib-title-conventional-commits,CC1 # different way of doing the same
+GITLINT_CONTRIB=contrib-title-conventional-commits,CC1 gitlint # using env variable
```
```ini
#.gitlint
[general]
-ignore=T1,body-min-length
+contrib=contrib-title-conventional-commits,CC1
```
-## debug
+### staged
-Enable debugging output.
+Fetch additional meta-data from the local `repository when manually passing a commit message to gitlint via stdin or `--commit-msg`.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- false | >= 0.7.1 | `--debug`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ false | >= 0.13.0 | `--staged` | `GITLINT_STAGED`
-### Examples
+#### Examples
```sh
# CLI
-gitlint --debug
-# --debug is special, the following does NOT work
-# gitlint -c general.debug=true
+gitlint --staged
+gitlint -c general.staged=true # different way of doing the same
+GITLINT_STAGED=1 gitlint # using env variable
+```
+```ini
+#.gitlint
+[general]
+staged=true
```
-## target
+### ignore-stdin
-Target git repository gitlint should be linting against.
+Ignore any stdin data. Sometimes useful when running gitlint in a CI server.
-Default value | gitlint version | commandline flag
----------------------------|------------------|-------------------
- (empty) | >= 0.8.0 | `--target`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ false | >= 0.12.0 | `--ignore-stdin` | `GITLINT_IGNORE_STDIN`
-### Examples
+#### Examples
```sh
# CLI
-gitlint --target=/home/joe/myrepo/
-gitlint -c general.target=/home/joe/myrepo/ # different way of doing the same
+gitlint --ignore-stdin
+gitlint -c general.ignore-stdin=true # different way of doing the same
+GITLINT_IGNORE_STDIN=1 gitlint # using env variable
```
```ini
#.gitlint
[general]
-target=/home/joe/myrepo/
+ignore-stdin=true
```
-## extra-path
+### ignore-merge-commits
-Path where gitlint looks for [user-defined rules](user_defined_rules.md).
+Whether or not to ignore merge commits.
-Default value | gitlint version | commandline flag
----------------------------|------------------|-------------------
- (empty) | >= 0.8.0 | `--extra-path`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ true | >= 0.7.0 | Not Available | Not Available
-### Examples
+#### Examples
```sh
# CLI
-gitlint --extra-path=/home/joe/rules/
-gitlint -c general.extra-path=/home/joe/rules/ # different way of doing the same
+gitlint -c general.ignore-merge-commits=false
```
```ini
#.gitlint
[general]
-extra-path=/home/joe/rules/
+ignore-merge-commits=false
```
-## contrib
+### ignore-revert-commits
-[Contrib rules](contrib_rules) to enable.
+Whether or not to ignore revert commits.
-Default value | gitlint version | commandline flag
----------------------------|------------------|-------------------
- (empty) | >= 0.12.0 | `--contrib`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ true | >= 0.13.0 | Not Available | Not Available
-### Examples
+#### Examples
```sh
# CLI
-gitlint --contrib=contrib-title-conventional-commits,CC1
-gitlint -c general.contrib=contrib-title-conventional-commits,CC1 # different way of doing the same
+gitlint -c general.ignore-revert-commits=false
```
```ini
#.gitlint
[general]
-contrib=contrib-title-conventional-commits,CC1
+ignore-revert-commits=false
```
-## ignore-stdin
-Ignore any stdin data. Sometimes useful when running gitlint in a CI server.
+### ignore-fixup-commits
+
+Whether or not to ignore [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- false | >= 0.12.0 | `--ignore-stdin`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ true | >= 0.9.0 | Not Available | Not Available
-### Examples
+#### Examples
```sh
# CLI
-gitlint --ignore-stdin
-gitlint -c general.ignore-stdin=true # different way of doing the same
+gitlint -c general.ignore-fixup-commits=false
```
```ini
#.gitlint
[general]
-ignore-stdin=true
+ignore-fixup-commits=false
```
-## staged
+### ignore-squash-commits
-Fetch additional meta-data from the local `repository when manually passing a commit message to gitlint via stdin or ```--commit-msg```.
+Whether or not to ignore [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) commits.
-Default value | gitlint version | commandline flag
----------------|------------------|-------------------
- false | >= 0.13.0 | `--staged`
+Default value | gitlint version | commandline flag | environment variable
+---------------|------------------|-------------------|-----------------------
+ true | >= 0.9.0 | Not Available | Not Available
-### Examples
+#### Examples
```sh
# CLI
-gitlint --staged
-gitlint -c general.staged=true # different way of doing the same
+gitlint -c general.ignore-squash-commits=false
```
```ini
#.gitlint
[general]
-staged=true
+ignore-squash-commits=false
``` \ No newline at end of file
diff --git a/docs/contrib_rules.md b/docs/contrib_rules.md
index a4f4f0d..e376fb8 100644
--- a/docs/contrib_rules.md
+++ b/docs/contrib_rules.md
@@ -7,7 +7,7 @@ Contrib rules are meant to augment default gitlint behavior by providing users w
forcing these rules on all gitlint users. This also means that users don't have to
re-implement these commonly used rules themselves as [user-defined](user_defined_rules) rules.
-To enable certain contrib rules, you can use the ```--contrib``` flag.
+To enable certain contrib rules, you can use the `--contrib` flag.
```sh
$ cat examples/commit-message-1 | gitlint --contrib contrib-title-conventional-commits,CC1
1: CC1 Body does not contain a 'Signed-Off-By' line
@@ -20,7 +20,7 @@ $ cat examples/commit-message-1 | gitlint --contrib contrib-title-conventional-c
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."
```
-Same thing using a ```.gitlint``` file:
+Same thing using a `.gitlint` file:
```ini
[general]
@@ -36,7 +36,7 @@ types = bugfix,user-story,epic
You can also configure contrib rules using [any of the other ways to configure gitlint](configuration.md).
-# Available Contrib Rules
+## Available Contrib Rules
ID | Name | gitlint version | Description
------|-------------------------------------|------------------ |-------------------------------------------
@@ -53,7 +53,7 @@ CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [C
Name | gitlint version | Default | Description
---------------|--------------------|--------------|----------------------------------
-types | >= 0.12.0 | `fix,feat,chore,docs,style,refactor,perf,test,revert` | Comma separated list of allowed commit types.
+types | >= 0.12.0 | `fix,feat,chore,docs,style,refactor,perf,test,revert,ci,build` | Comma separated list of allowed commit types.
## CC1: contrib-requires-signed-off-by ##
@@ -63,5 +63,5 @@ ID | Name | gitlint version | Description
CC1 | contrib-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.
-# Contributing Contrib rules
-We'd love for you to contribute new Contrib rules to gitlint or improve existing ones! Please visit the [Contributing](contributing) page on how to get started. \ No newline at end of file
+## Contributing Contrib rules
+We'd love for you to contribute new Contrib rules to gitlint or improve existing ones! Please visit the [Contributing](contributing) page on how to get started.
diff --git a/docs/contributing.md b/docs/contributing.md
index 0cd6eaf..f0d2d30 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -9,40 +9,47 @@ your interest!
We maintain a [loose roadmap on our wiki](https://github.com/jorisroovers/gitlint/wiki/Roadmap), but
that's open to a lot of change and input.
-# Guidelines
+## Guidelines
When contributing code, please consider all the parts that are typically required:
-- [Unit tests](https://github.com/jorisroovers/gitlint/tree/master/gitlint/tests) (automatically
+- [Unit tests](https://github.com/jorisroovers/gitlint/tree/main/gitlint/tests) (automatically
[enforced by CI](https://github.com/jorisroovers/gitlint/actions)). Please consider writing
new ones for your functionality, not only updating existing ones to make the build pass.
-- [Integration tests](https://github.com/jorisroovers/gitlint/tree/master/qa) (also automatically
+- [Integration tests](https://github.com/jorisroovers/gitlint/tree/main/qa) (also automatically
[enforced by CI](https://github.com/jorisroovers/gitlint/actions)). Again, please consider writing new ones
for your functionality, not only updating existing ones to make the build pass.
-- [Documentation](https://github.com/jorisroovers/gitlint/tree/master/docs)
+- [Documentation](https://github.com/jorisroovers/gitlint/tree/main/docs)
Since we want to maintain a high standard of quality, all of these things will have to be done regardless before code
can make it as part of a release. If you can already include them as part of your PR, it's a huge timesaver for us
and it's likely that your PR will be merged and released a lot sooner. Thanks!
-# Development #
+!!! Important
+ **On the topic of releases**: Gitlint releases typically go out when there's either enough new features and fixes
+ to make it worthwhile or when there's a critical fix for a bug that fundamentally breaks gitlint. While the amount
+ of overhead of doing a release isn't huge, it's also not zero. In practice this means that it might take weeks
+ or months before merged code actually gets released - we know that can be frustrating but please understand it's
+ a well-considered trade-off based on available time.
+
+## Development
There is a Vagrantfile in this repository that can be used for development.
-```bash
+```sh
vagrant up
vagrant ssh
```
Or you can choose to use your local environment:
-```bash
+```sh
virtualenv .venv
pip install -r requirements.txt -r test-requirements.txt -r doc-requirements.txt
python setup.py develop
```
To run tests:
-```bash
+```sh
./run_tests.sh # run unit tests and print test coverage
./run_test.sh gitlint/tests/test_body_rules.py::BodyRuleTests::test_body_missing # run a single test
./run_tests.sh --no-coverage # run unit tests without test coverage
@@ -54,16 +61,14 @@ To run tests:
./run_tests.sh --git # inception: run gitlint against itself
./run_tests.sh --lint # run pylint checks
./run_tests.sh --all # Run unit, integration, pep8 and gitlint checks
-
-
```
-The ```Vagrantfile``` comes with ```virtualenv```s for python 2.7, 3.5, 3.6, 3.7 and pypy2.
+The `Vagrantfile` comes with `virtualenv`s for python 2.7, 3.5, 3.6, 3.7, 3.8, 3.9 and pypy2.
You can easily run tests against specific python environments by using the following commands *inside* of the Vagrant VM:
-```
+```sh
./run_tests.sh --envs 27 # Run the unit tests against Python 2.7
-./run_tests.sh --envs 27,35,pypy2 # Run the unit tests against Python 2.7, Python 3.5 and Pypy2
-./run_tests.sh --envs 27,35 --pep8 # Run pep8 checks against Python 2.7 and Python 3.5 (also works for ```--git```, ```--integration```, ```--pep8```, ```--stats``` and ```--lint```).
+./run_tests.sh --envs 27,37,pypy2 # Run the unit tests against Python 2.7, Python 3.7 and Pypy2
+./run_tests.sh --envs 27,37 --pep8 # Run pep8 checks against Python 2.7 and Python 3.7 (also works for --git, --integration, --pep8, --stats and --lint.
./run_tests.sh --envs all --all # Run all tests against all environments
./run_tests.sh --all-env --all # Idem: Run all tests against all environments
```
@@ -71,29 +76,29 @@ You can easily run tests against specific python environments by using the follo
!!! important
Gitlint commits and pull requests are gated on all of our tests and checks.
-# Packaging #
+## Packaging
To see the package description in HTML format
-```
+```sh
pip install docutils
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
python setup.py --long-description | rst2html.py > output.html
```
-# Documentation #
+## Documentation
We use [mkdocs](https://www.mkdocs.org/) for generating our documentation from markdown.
To use it, do the following outside of the vagrant box (on your host machine):
-```bash
+```sh
pip install -r doc-requirements.txt # install doc requirements
mkdocs serve
```
Then access the documentation website on your host machine on [http://localhost:8000]().
-# Tools #
-We keep a small set of scripts in the ```tools/``` directory:
+## Tools
+We keep a small set of scripts in the `tools/` directory:
```sh
tools/create-test-repo.sh # Create a test git repo in your /tmp directory
@@ -101,7 +106,7 @@ tools/windows/create-test-repo.bat # Windows: create git test repo
tools/windows/run_tests.bat # Windows run unit tests
```
-# Contrib rules
+## Contrib rules
Since gitlint 0.12.0, we support [Contrib rules](../contrib_rules): community contributed rules that are part of gitlint
itself. Thanks for considering to add a new one to gitlint!
@@ -110,13 +115,13 @@ Then, we suggest taking the following approach to add a Contrib rule:
1. **Write your rule as a [user-defined rule](../user_defined_rules)**. In terms of code, Contrib rules are identical to
user-defined rules, they just happen to have their code sit within the gitlint codebase itself.
-2. **Add your user-defined rule to gitlint**. You should put your file(s) in the [gitlint/contrib/rules](https://github.com/jorisroovers/gitlint/tree/master/gitlint/contrib/rules) directory.
-3. **Write unit tests**. The gitlint codebase contains [Contrib rule test files you can copy and modify](https://github.com/jorisroovers/gitlint/tree/master/gitlint/tests/contrib).
-4. **Write documentation**. In particular, you should update the [gitlint/docs/contrib_rules.md](https://github.com/jorisroovers/gitlint/blob/master/docs/contrib_rules.md) file with details on your Contrib rule.
+2. **Add your user-defined rule to gitlint**. You should put your file(s) in the [gitlint/contrib/rules](https://github.com/jorisroovers/gitlint/tree/main/gitlint/contrib/rules) directory.
+3. **Write unit tests**. The gitlint codebase contains [Contrib rule test files you can copy and modify](https://github.com/jorisroovers/gitlint/tree/main/gitlint/tests/contrib/rules).
+4. **Write documentation**. In particular, you should update the [gitlint/docs/contrib_rules.md](https://github.com/jorisroovers/gitlint/blob/main/docs/contrib_rules.md) file with details on your Contrib rule.
5. **Create a Pull Request**: code review typically requires a bit of back and forth. Thanks for your contribution!
-## Contrib rule requirements
+### Contrib rule requirements
If you follow the steps above and follow the existing gitlint conventions wrt naming things, you should already be fairly close to done.
In case you're looking for a slightly more formal spec, here's what gitlint requires of Contrib rules.
diff --git a/docs/extra.js b/docs/extra.js
new file mode 100644
index 0000000..4af1fa4
--- /dev/null
+++ b/docs/extra.js
@@ -0,0 +1,5 @@
+document.addEventListener("DOMContentLoaded", function () {
+ document.querySelectorAll("table").forEach(function (table) {
+ table.classList.add("docutils");
+ });
+}); \ No newline at end of file
diff --git a/docs/index.md b/docs/index.md
index 3155b19..c179c9e 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,4 +1,4 @@
-# Intro
+# Introduction
Gitlint is a git commit message linter written in python: it checks your commit messages for style.
Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or as part of your gating script in a
@@ -13,7 +13,11 @@ Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or
have a look at [fit-commit](https://github.com/m1foley/fit-commit) (Ruby),
[node-commit-msg](https://github.com/clns/node-commit-msg) (Node.js) or [commitlint](http://marionebl.github.io/commitlint) (Node.js).
-## Features ##
+
+!!! important
+ **Gitlint will soon be dropping support for Python 2.7 and Python 3.5 as they [have reached End-Of-Life](https://endoflife.date/python)**.
+
+## Features
- **Commit message hook**: [Auto-trigger validations against new commit message right when you're committing](#using-gitlint-as-a-commit-msg-hook). Also [works with pre-commit](#using-gitlint-through-pre-commit).
- **Easily integrated**: Gitlint is designed to work [with your own scripts or CI system](#using-gitlint-in-a-ci-environment).
- **Sane defaults:** Many of gitlint's validations are based on
@@ -24,14 +28,13 @@ useful throughout the years.
- **Easily configurable:** Gitlint has sane defaults, but [you can also easily customize it to your own liking](configuration.md).
- **Community contributed rules**: Conventions that are common but not universal [can be selectively enabled](contrib_rules).
- **User-defined rules:** Want to do more then what gitlint offers out of the box? Write your own [user defined rules](user_defined_rules.md).
- - **Broad python version support:** Gitlint supports python versions 2.7, 3.5+, PyPy2 and PyPy3.5.
- **Full unicode support:** Lint your Russian, Chinese or Emoji commit messages with ease!
- **Production-ready:** Gitlint checks a lot of the boxes you're looking for: actively maintained, high unit test coverage, integration tests,
python code standards (pep8, pylint), good documentation, widely used, proven track record.
-# Getting Started
-## Installation
-```bash
+## Getting Started
+### Installation
+```sh
# Pip is recommended to install the latest version
pip install gitlint
@@ -43,10 +46,12 @@ brew install gitlint
apt-get install gitlint
# Docker: https://hub.docker.com/r/jorisroovers/gitlint
-docker run -v $(pwd):/repo jorisroovers/gitlint
+docker run --ulimit nofile=1024 -v $(pwd):/repo jorisroovers/gitlint
+# NOTE: --ulimit is required to work around a limitation in Docker
+# Details: https://github.com/jorisroovers/gitlint/issues/129
```
-## Usage
+### Usage
```sh
# Check the last commit message
gitlint
@@ -64,7 +69,7 @@ gitlint install-hook
```
Output example:
-```bash
+```sh
$ cat examples/commit-message-2 | gitlint
1: T1 Title exceeds max length (134>80): "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping "
1: T2 Title has trailing whitespace: "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping "
@@ -77,11 +82,11 @@ $ cat examples/commit-message-2 | gitlint
!!! note
The returned exit code equals the number of errors found. [Some exit codes are special](index.md#exit-codes).
-# Configuration
+## Configuration
For in-depth documentation of general and rule-specific configuration options, have a look at the [Configuration](configuration.md) and [Rules](rules.md) pages.
-Short example ```.gitlint``` file ([full reference](configuration.md)):
+Short example `.gitlint` file ([full reference](configuration.md)):
```ini
[general]
@@ -103,7 +108,7 @@ line-length=123
Example use of flags:
-```bash
+```sh
# Change gitlint's verbosity.
$ gitlint -v
# Ignore certain rules
@@ -160,13 +165,13 @@ Commands:
```
-# Using gitlint as a commit-msg hook ##
+## Using gitlint as a commit-msg hook
_Introduced in gitlint v0.4.0_
-You can also install gitlint as a git ```commit-msg``` hook so that gitlint checks your commit messages automatically
+You can also install gitlint as a git `commit-msg` hook so that gitlint checks your commit messages automatically
after each commit.
-```bash
+```sh
gitlint install-hook
# To remove the hook
gitlint uninstall-hook
@@ -174,13 +179,13 @@ gitlint uninstall-hook
!!! important
- Gitlint cannot work together with an existing hook. If you already have a ```.git/hooks/commit-msg```
- file in your local repository, gitlint will refuse to install the ```commit-msg``` hook. Gitlint will also only
+ Gitlint cannot work together with an existing hook. If you already have a `.git/hooks/commit-msg`
+ file in your local repository, gitlint will refuse to install the `commit-msg` hook. Gitlint will also only
uninstall unmodified commit-msg hooks that were installed by gitlint.
If you're looking to use gitlint in conjunction with other hooks, you should consider
[using gitlint with pre-commit](#using-gitlint-through-pre-commit).
-# Using gitlint through [pre-commit](https://pre-commit.com)
+## Using gitlint through [pre-commit](https://pre-commit.com)
`gitlint` can be configured as a plugin for the `pre-commit` git hooks
framework. Simply add the configuration to your `.pre-commit-config.yaml`:
@@ -198,10 +203,10 @@ pre-commit install --hook-type commit-msg
```
!!! important
- It's important that you run ```pre-commit install --hook-type commit-msg```, even if you've already used
- ```pre-commit install``` before. ```pre-commit install``` does **not** install commit-msg hooks by default!
+ It's important that you run `pre-commit install --hook-type commit-msg`, even if you've already used
+ `pre-commit install` before. `pre-commit install` does **not** install commit-msg hooks by default!
-To manually trigger gitlint using ```pre-commit``` for your last commit message, use the following command:
+To manually trigger gitlint using `pre-commit` for your last commit message, use the following command:
```sh
pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG
```
@@ -219,8 +224,8 @@ your `.pre-commit-config.yaml` file like so:
args: [--contrib=CT1, --msg-filename]
```
-# Using gitlint in a CI environment ##
-By default, when just running ```gitlint``` without additional parameters, gitlint lints the last commit in the current
+## Using gitlint in a CI environment
+By default, when just running `gitlint` without additional parameters, gitlint lints the last commit in the current
working directory.
This makes it easy to use gitlint in a CI environment (Jenkins, TravisCI, Github Actions, pre-commit, CircleCI, Gitlab, etc).
@@ -229,22 +234,22 @@ In fact, this is exactly what we do ourselves: on every commit,
This will cause the build to fail when we submit a bad commit message.
Alternatively, gitlint will also lint any commit message that you feed it via stdin like so:
-```bash
+```sh
# lint the last commit message
git log -1 --pretty=%B | gitlint
# lint a specific commit: 62c0519
git log -1 --pretty=%B 62c0519 | gitlint
```
-Note that gitlint requires that you specify ```--pretty=%B``` (=only print the log message, not the metadata),
-future versions of gitlint might fix this and not require the ```--pretty``` argument.
+Note that gitlint requires that you specify `--pretty=%B` (=only print the log message, not the metadata),
+future versions of gitlint might fix this and not require the `--pretty` argument.
-## Linting a range of commits ##
+## Linting a range of commits
_Introduced in gitlint v0.9.0 (experimental in v0.8.0)_
-Gitlint allows users to commit a number of commits at once like so:
+Gitlint allows users to lint a number of commits at once like so:
-```bash
+```sh
# Lint a specific commit range:
gitlint --commits "019cf40...d6bc75a"
# You can also use git's special references:
@@ -253,16 +258,14 @@ gitlint --commits "origin..HEAD"
gitlint --commits "019cf40^...019cf40"
```
-The ```--commits``` flag takes a **single** refspec argument or commit range. Basically, any range that is understood
+The `--commits` flag takes a **single** refspec argument or commit range. Basically, any range that is understood
by [git rev-list](https://git-scm.com/docs/git-rev-list) as a single argument will work.
-Prior to v0.8.1 gitlint didn't support this feature. However, older versions of gitlint can still lint a range or set
-of commits at once by creating a simple bash script that pipes the commit messages one by one into gitlint. This
-approach can still be used with newer versions of gitlint in case ```--commits``` doesn't provide the flexibility you
-are looking for.
+For cases where the `--commits` option doesn't provide the flexibility you need, you can always use a simple shell
+script to lint an arbitrary set of commits, like shown in the example below.
-```bash
-#!/bin/bash
+```sh
+#!/bin/sh
for commit in $(git rev-list master); do
commit_msg=$(git log -1 --pretty=%B $commit)
@@ -275,10 +278,10 @@ done
!!! note
One downside to this approach is that you invoke gitlint once per commit vs. once per set of commits.
This means you'll incur the gitlint startup time once per commit, making this approach rather slow if you want to
- lint a large set of commits. Always use ```--commits``` if you can to avoid this performance penalty.
+ lint a large set of commits. Always use `--commits` if you can to avoid this performance penalty.
-# Merge, fixup and squash commits ##
+## Merge, fixup, squash and revert commits
_Introduced in gitlint v0.7.0 (merge), v0.9.0 (fixup, squash) and v0.13.0 (revert)_
**Gitlint ignores merge, revert, fixup and squash commits by default.**
@@ -298,20 +301,20 @@ short-lived and not intended to make it into the final commit history. In additi
(e.g. [title-max-length](rules.md#t1-title-max-length)) which is often undesirable.
In case you *do* want to lint these commit messages, you can disable this behavior by setting the
-general ```ignore-merge-commits```, ```ignore-revert-commits```, ```ignore-fixup-commits``` or
-```ignore-squash-commits``` option to ```false```
+general `ignore-merge-commits`, `ignore-revert-commits`, `ignore-fixup-commits` or
+`ignore-squash-commits` option to `false`
[using one of the various ways to configure gitlint](configuration.md).
-# Ignoring commits ##
+## Ignoring commits
_Introduced in gitlint v0.10.0_
-You can configure gitlint to ignore specific commits.
+You can configure gitlint to ignore specific commits or parts of a commit.
One way to do this, is to by [adding a gitline-ignore line to your commit message](configuration.md#commit-specific-config).
If you have a case where you want to ignore a certain type of commits all-together, you can
use gitlint's *ignore* rules.
-Here's an example gitlint file that configures gitlint to ignore rules ```title-max-length``` and ```body-min-length```
+Here's an example gitlint file that configures gitlint to ignore rules `title-max-length` and `body-min-length`
for all commits with a title starting with *"Release"*.
```ini
@@ -328,13 +331,88 @@ regex=(.*)release(.*)
ignore=all
```
+If you just want to ignore certain lines in a commit, you can do that using the
+[ignore-body-lines](rules.md#i3-ignore-body-lines) rule.
+
+```ini
+# Ignore all lines that start with 'Co-Authored-By'
+[ignore-body-lines]
+regex=^Co-Authored-By
+```
+
+!!! warning
+
+ When ignoring specific lines, gitlint will no longer be aware of them while applying other rules.
+ This can sometimes be confusing for end-users, especially as line numbers of violations will typically no longer
+ match line numbers in the original commit message. Make sure to educate your users accordingly.
+
!!! note
- Right now it's not possible to write user-defined ignore rules to handle more complex use-cases.
- This is however something that we'd like to implement in a future version. If this is something you're interested in
- please let us know by [opening an issue](https://github.com/jorisroovers/gitlint/issues).
+ If you want to implement more complex ignore rules according to your own logic, you can do so using [user-defined
+ configuration rules](user_defined_rules.md#configuration-rules).
+
+## Named Rules
+
+Introduced in gitlint v0.14.0
+
+Named rules allow you to have multiple of the same rules active at the same time, which allows you to
+enforce the same rule multiple times but with different options. Named rules are so-called because they require an
+additional unique identifier (i.e. the rule *name*) during configuration.
+
+!!! warning
+
+ Named rules is an advanced topic. It's easy to make mistakes by defining conflicting instances of the same rule.
+ For example, by defining 2 `body-max-line-length` rules with different `line-length` options, you obviously create
+ a conflicting situation. Gitlint does not do any resolution of such conflicts, it's up to you to make sure
+ any configuration is non-conflicting. So caution advised!
+
+Defining a named rule is easy, for example using your `.gitlint` file:
+
+```ini
+# By adding the following section, you will add a second instance of the
+# title-must-not-contain-word (T5) rule (in addition to the one that is enabled
+# by default) with the name 'extra-words'.
+[title-must-not-contain-word:extra-words]
+words=foo,bar
+
+# So the generic form is
+# [<rule-id-or-name>:<your-chosen-name>]
+# Another example, referencing the rule type by id
+[T5:more-words]
+words=hur,dur
+
+# You can add as many additional rules and you can name them whatever you want
+# The only requirement is that names cannot contain whitespace or colons (:)
+[title-must-not-contain-word:This-Can_Be*Whatever$YouWant]
+words=wonderwoman,batman,power ranger
+```
+
+When executing gitlint, you will see the violations from the default `title-must-not-contain-word (T5)` rule, as well as
+the violations caused by the additional Named Rules.
+
+```sh
+$ gitlint
+1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: foo wonderwoman hur bar"
+1: T5:This-Can_Be*Whatever$YouWant Title contains the word 'wonderwoman' (case-insensitive): "WIP: foo wonderwoman hur bar"
+1: T5:extra-words Title contains the word 'foo' (case-insensitive): "WIP: foo wonderwoman hur bar"
+1: T5:extra-words Title contains the word 'bar' (case-insensitive): "WIP: foo wonderwoman hur bar"
+1: T5:more-words Title contains the word 'hur' (case-insensitive): "WIP: foo wonderwoman hur bar"
+```
+
+Named rules are further treated identical to all other rules in gitlint:
+
+- You can reference them by their full name, when e.g. adding them to your `ignore` configuration
+```ini
+# .gitlint file example
+[general]
+ignore=T5:more-words,title-must-not-contain-word:extra-words
+```
+
+- You can use them to instantiate multiple of the same [user-defined rule](user_defined_rules.md)
+- You can configure them using [any of the ways you can configure regular gitlint rules](configuration.md)
+
-# Exit codes ##
+## Exit codes
Gitlint uses the exit code as a simple way to indicate the number of violations found.
Some exit codes are used to indicate special errors as indicated in the table below.
@@ -346,6 +424,6 @@ to 252.
Exit Code | Description
-----------|------------------------------------------------------------
-253 | Wrong invocation of the ```gitlint``` command.
+253 | Wrong invocation of the `gitlint` command.
254 | Something went wrong when invoking git.
-255 | Invalid gitlint configuration
+255 | Invalid gitlint configuration \ No newline at end of file
diff --git a/docs/rules.md b/docs/rules.md
index 173c5b1..178f962 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -1,9 +1,12 @@
-# Overview #
+# Overview
-The table below shows an overview of all gitlint's built-in rules.
-Note that you can also [write your own user-defined rule](user_defined_rules.md) in case you don't find
+The table below shows an overview of all gitlint's built-in rules, with more specific details further down the page.
+
+Gitlint also has [community **contrib**uted rules](contrib_rules.md) which are not listed here as they're disabled by default.
+
+In addition, you can also [write your own user-defined rule](user_defined_rules.md) in case you don't find
what you're looking for.
-The rest of this page contains details on the available configuration options for each built-in rule.
+
ID | Name | gitlint version | Description
------|-----------------------------|-------------------|-------------------------------------------
@@ -13,7 +16,8 @@ T3 | title-trailing-punctuation | >= 0.1.0 | Title cannot have trai
T4 | title-hard-tab | >= 0.1.0 | Title cannot contain hard tab characters (\t)
T5 | title-must-not-contain-word | >= 0.1.0 | Title cannot contain certain words (default: "WIP")
T6 | title-leading-whitespace | >= 0.4.0 | Title cannot have leading whitespace (space or tab)
-T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: .*)
+T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: None)
+T8 | title-max-length | >= 0.14.0 | Title length must be &gt; 5 chars.
B1 | body-max-line-length | >= 0.1.0 | Lines in the body must be &lt; 80 chars
B2 | body-trailing-whitespace | >= 0.1.0 | Body cannot have trailing whitespace (space or tab)
B3 | body-hard-tab | >= 0.1.0 | Body cannot contain hard tab characters (\t)
@@ -21,107 +25,181 @@ B4 | body-first-line-empty | >= 0.1.0 | First line of the body
B5 | body-min-length | >= 0.4.0 | Body length must be at least 20 characters
B6 | body-is-missing | >= 0.4.0 | Body message must be specified
B7 | body-changed-file-mention | >= 0.4.0 | Body must contain references to certain files if those files are changed in the last commit
+B8 | body-match-regex | >= 0.14.0 | Title must match a given regex (default: None)
M1 | author-valid-email | >= 0.9.0 | Author email address must be a valid email address
I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title
I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body
+I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex
+
-## T1: title-max-length ##
+## T1: title-max-length
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T1 | title-max-length | >= 0.1 | Title length must be &lt; 72 chars.
-### Options ###
+### Options
Name | gitlint version | Default | Description
---------------|-----------------|---------|----------------------------------
line-length | >= 0.2 | 72 | Maximum allowed title length
-## T2: title-trailing-whitespace ##
+### Examples
+
+#### .gitlint
+
+```ini
+# Titles should be max 72 chars
+[title-max-length]
+line-length=72
+
+# It's the 21st century, titles can be 120 chars long
+[title-max-length]
+line-length=120
+```
+
+## T2: title-trailing-whitespace
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T2 | title-trailing-whitespace | >= 0.1 | Title cannot have trailing whitespace (space or tab)
-## T3: title-trailing-punctuation ##
+## T3: title-trailing-punctuation
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T3 | title-trailing-punctuation | >= 0.1 | Title cannot have trailing punctuation (?:!.,;)
-## T4: title-hard-tab ##
+## T4: title-hard-tab
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T4 | title-hard-tab | >= 0.1 | Title cannot contain hard tab characters (\t)
-## T5: title-must-not-contain-word ##
+## T5: title-must-not-contain-word
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T5 | title-must-not-contain-word | >= 0.1 | Title cannot contain certain words (default: "WIP")
-### Options ###
+### Options
Name | gitlint version | Default | Description
---------------|-----------------|---------|----------------------------------
words | >= 0.3 | WIP | Comma-separated list of words that should not be used in the title. Matching is case insensitive
-## T6: title-leading-whitespace ##
+### Examples
+
+#### .gitlint
+
+```ini
+# Ensure the title doesn't contain swear words
+[title-must-not-contain-word]
+words=crap,darn,damn
+```
+
+## T6: title-leading-whitespace
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T6 | title-leading-whitespace | >= 0.4 | Title cannot have leading whitespace (space or tab)
-## T7: title-match-regex ##
+## T7: title-match-regex
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
T7 | title-match-regex | >= 0.5 | Title must match a given regex (default: .*)
-### Options ###
+### Options
Name | gitlint version | Default | Description
---------------|-----------------|---------|----------------------------------
-regex | >= 0.5 | .* | [Python-style regular expression](https://docs.python.org/3.5/library/re.html) that the title should match.
+regex | >= 0.5 | .* | [Python regex](https://docs.python.org/library/re.html) that the title should match.
+
+### Examples
+
+#### .gitlint
+
+```ini
+# Ensure every title starts with a user-story like US123
+[title-match-regex]
+regex=^US[1-9][0-9]*
+```
-## B1: body-max-line-length ##
+## T8: title-min-length ##
+
+ID | Name | gitlint version | Description
+------|-----------------------------|-----------------|-------------------------------------------
+T1 | title-min-length | >= | Title length must be &gt; 5 chars.
+
+
+### Options
+
+Name | gitlint version | Default | Description
+---------------|-----------------|---------|----------------------------------
+min-length | >= 0.14.0 | 5 | Minimum required title length
+
+### Examples
+
+#### .gitlint
+
+```ini
+# Titles should be min 3 chars
+[title-min-length]
+min-length=3
+```
+
+## B1: body-max-line-length
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
B1 | body-max-line-length | >= 0.1 | Lines in the body must be &lt; 80 chars
-### Options ###
+### Options
Name | gitlint version | Default | Description
---------------|-----------------|---------|----------------------------------
line-length | >= 0.2 | 80 | Maximum allowed line length in the commit message body
-## B2: body-trailing-whitespace ##
+### Examples
+
+#### .gitlint
+
+```ini
+# It's the 21st century, lines can be 120 chars long
+[body-max-line-length]
+line-length=120
+
+# Your tool prefers 72
+[body-max-line-length]
+line-length=72
+```
+
+## B2: body-trailing-whitespace
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
B2 | body-trailing-whitespace | >= 0.1 | Body cannot have trailing whitespace (space or tab)
-## B3: body-hard-tab ##
+## B3: body-hard-tab
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
B3 | body-hard-tab | >= 0.1 | Body cannot contain hard tab characters (\t)
-## B4: body-first-line-empty ##
+## B4: body-first-line-empty
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
B4 | body-first-line-empty | >= 0.1 | First line of the body (second line of commit message) must be empty
-## B5: body-min-length ##
+## B5: body-min-length
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
@@ -133,34 +211,83 @@ Name | gitlint version | Default | Description
---------------|-----------------|---------|----------------------------------
min-length | >= 0.4 | 20 | Minimum number of required characters in body
-## B6: body-is-missing ##
+### Examples
+
+#### .gitlint
+
+```ini
+# You want *something* in every commit body, but doesn't have to be as long as 20 chars.
+[body-min-length]
+min-length=5
+
+# You want a more elaborate message in every commit body
+[body-min-length]
+min-length=100
+```
+
+## B6: body-is-missing
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
B6 | body-is-missing | >= 0.4 | Body message must be specified
-### Options ###
+### Options
Name | gitlint version | Default | Description
----------------------|-----------------|-----------|----------------------------------
ignore-merge-commits | >= 0.4 | true | Whether this rule should be ignored during merge commits. Allowed values: true,false.
-## B7: body-changed-file-mention ##
+## B7: body-changed-file-mention
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
B7 | body-changed-file-mention | >= 0.4 | Body must contain references to certain files if those files are changed in the last commit
-### Options ###
+### Options
Name | gitlint version | Default | Description
----------------------|-----------------|--------------|----------------------------------
files | >= 0.4 | (empty) | Comma-separated list of files that need to an explicit mention in the commit message in case they are changed.
+### Examples
+
+#### .gitlint
+
+```ini
+# Prevent that certain sensitive files are committed by mistake by forcing users to mention them explicitly if they're
+# deliberately changing them
+[body-changed-file-mention]
+files=generated.xml,secrets.txt,private-key.pem
+```
+
+## B8: body-match-regex
+ID | Name | gitlint version | Description
+------|-----------------------------|-----------------|-------------------------------------------
+B8 | body-match-regex | >= 0.14 | Body must match a given regex
+
+### Options
+
+Name | gitlint version | Default | Description
+----------------------|-----------------|--------------|----------------------------------
+regex | >= 0.14 | None | [Python regex](https://docs.python.org/library/re.html) that the title should match.
+
+### Examples
+
+#### .gitlint
+
+```ini
+# Ensure the body ends with Reviewed-By: <some value>
+[body-match-regex]
+regex=Reviewed-By:(.*)$
+
+# Ensure body contains the word "Foo" somewhere
+[body-match-regex]
+regex=(*.)Foo(.*)
+```
-## M1: author-valid-email ##
+## M1: author-valid-email
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
@@ -172,30 +299,36 @@ M1 | author-valid-email | >= 0.8.3 | Author email address mus
-### Options ###
+### Options
Name | gitlint version | Default | Description
----------------------|-------------------|------------------------------|----------------------------------
-regex | >= 0.9.0 | ```[^@ ]+@[^@ ]+\.[^@ ]+``` | Regex the commit author email address is matched against
+regex | >= 0.9.0 | `[^@ ]+@[^@ ]+\.[^@ ]+` | [Python regex](https://docs.python.org/library/re.html) the commit author email address is matched against
-!!! note
- An often recurring use-case is to only allow email addresses from a certain domain. The following regular expression achieves this: ```[^@]+@foo.com```
+### Examples
+#### .gitlint
+
+```ini
+# Only allow email addresses from a foo.com domain
+[author-valid-email]
+regex=[^@]+@foo.com
+```
-## I1: ignore-by-title ##
+## I1: ignore-by-title
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
I1 | ignore-by-title | >= 0.10.0 | Ignore a commit based on matching its title.
-### Options ###
+### Options
Name | gitlint version | Default | Description
----------------------|-------------------|------------------------------|----------------------------------
-regex | >= 0.10.0 | None | Regex to match against commit title. On match, the commit will be ignored.
-ignore | >= 0.10.0 | all | Comma-seperated list of rule names or ids to ignore when this rule is matched.
+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.
+ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched.
### Examples
@@ -211,19 +344,19 @@ ignore=title-max-length,body-min-length
# ignore=all
```
-## I2: ignore-by-body ##
+## I2: ignore-by-body
ID | Name | gitlint version | Description
------|-----------------------------|-----------------|-------------------------------------------
I2 | ignore-by-body | >= 0.10.0 | Ignore a commit based on matching its body.
-### Options ###
+### Options
Name | gitlint version | Default | Description
----------------------|-------------------|------------------------------|----------------------------------
-regex | >= 0.10.0 | None | Regex to match against each line of the body. On match, the commit will be ignored.
-ignore | >= 0.10.0 | all | Comma-seperated list of rule names or ids to ignore when this rule is matched.
+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.
+ignore | >= 0.10.0 | all | Comma-separated list of rule names or ids to ignore when this rule is matched.
### Examples
@@ -240,4 +373,35 @@ ignore=all
[ignore-by-body]
regex=(.*)release(.*)
ignore=T1,body-min-length,B6
-``` \ No newline at end of file
+```
+
+## I3: ignore-body-lines
+
+ID | Name | gitlint version | Description
+------|-----------------------------|-----------------|-------------------------------------------
+I3 | ignore-body-lines | >= 0.14.0 | Ignore certain lines in a commit body that match a regex.
+
+
+### Options
+
+Name | gitlint version | Default | Description
+----------------------|-------------------|------------------------------|----------------------------------
+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).
+
+### Examples
+
+#### .gitlint
+
+```ini
+# Ignore all lines that start with 'Co-Authored-By'
+[ignore-body-lines]
+regex=^Co-Authored-By
+
+# Ignore lines that start with 'Co-Authored-By' or with 'Signed-Off-By'
+[ignore-body-lines]
+regex=(^Co-Authored-By)|(^Signed-Off-By)
+
+# Ignore lines that contain 'foobar'
+[ignore-body-lines]
+regex=(.*)foobar(.*)
+```
diff --git a/docs/user_defined_rules.md b/docs/user_defined_rules.md
index a8a51d5..13ea544 100644
--- a/docs/user_defined_rules.md
+++ b/docs/user_defined_rules.md
@@ -3,22 +3,23 @@ _Introduced in gitlint v0.8.0_
Gitlint supports the concept of **user-defined** rules: the ability for users to write their own custom rules in python.
-In a nutshell, use ```--extra-path /home/joe/myextensions``` to point gitlint to a ```myextensions``` directory where it will search
+In a nutshell, use `--extra-path /home/joe/myextensions` to point gitlint to a `myextensions` directory where it will search
for python files containing gitlint rule classes. You can also specify a single python module, ie
-```--extra-path /home/joe/my_rules.py```.
+`--extra-path /home/joe/my_rules.py`.
-```bash
+```sh
cat examples/commit-message-1 | gitlint --extra-path examples/
# Example output of a user-defined Signed-Off-By rule
1: UC2 Body does not contain a 'Signed-Off-By Line'
# other violations were removed for brevity
```
-The `SignedOffBy` user-defined ```CommitRule``` was discovered by gitlint when it scanned
-[examples/gitlint/my_commit_rules.py](https://github.com/jorisroovers/gitlint/blob/master/examples/my_commit_rules.py),
-which is part of the examples directory that was passed via ```--extra-path```:
+The `SignedOffBy` user-defined `CommitRule` was discovered by gitlint when it scanned
+[examples/gitlint/my_commit_rules.py](https://github.com/jorisroovers/gitlint/blob/main/examples/my_commit_rules.py),
+which is part of the examples directory that was passed via `--extra-path`:
```python
+# -*- coding: utf-8 -*-
from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
@@ -35,6 +36,8 @@ class SignedOffBy(CommitRule):
id = "UC2"
def validate(self, commit):
+ self.log.debug("SignedOffBy: This will be visible when running `gitlint --debug`")
+
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
return
@@ -43,12 +46,12 @@ class SignedOffBy(CommitRule):
return [RuleViolation(self.id, msg, line_nr=1)]
```
-As always, ```--extra-path``` can also be set by adding it under the ```[general]``` section in your ```.gitlint``` file or using
+As always, `--extra-path` can also be set by adding it under the `[general]` section in your `.gitlint` file or using
[one of the other ways to configure gitlint](configuration.md).
-If you want to check whether your rules are properly discovered by gitlint, you can use the ```--debug``` flag:
+If you want to check whether your rules are properly discovered by gitlint, you can use the `--debug` flag:
-```bash
+```sh
$ gitlint --debug --extra-path examples/
# [output cut for brevity]
UC1: body-max-line-count
@@ -60,34 +63,35 @@ $ gitlint --debug --extra-path examples/
!!! Note
In most cases it's really the easiest to just copy an example from the
- [examples](https://github.com/jorisroovers/gitlint/tree/master/examples) directory and modify it to your needs.
+ [examples](https://github.com/jorisroovers/gitlint/tree/main/examples) directory and modify it to your needs.
The remainder of this page contains the technical details, mostly for reference.
-# Line and Commit Rules ##
-The ```SignedOffBy``` class above was an example of a user-defined ```CommitRule```. Commit rules are gitlint rules that
+## Line and Commit Rules
+The `SignedOffBy` class above was an example of a user-defined `CommitRule`. Commit rules are gitlint rules that
act on the entire commit at once. Once the rules are discovered, gitlint will automatically take care of applying them
to the entire commit. This happens exactly once per commit.
-A ```CommitRule``` contrasts with a ```LineRule```
-(see e.g.: [examples/my_line_rules.py](https://github.com/jorisroovers/gitlint/blob/master/examples/my_line_rules.py))
-in that a ```CommitRule``` is only applied once on an entire commit while a ```LineRule``` is applied for every line in the commit
-(you can also apply it once to the title using a ```target``` - see the examples section below).
+A `CommitRule` contrasts with a `LineRule`
+(see e.g.: [examples/my_line_rules.py](https://github.com/jorisroovers/gitlint/blob/main/examples/my_line_rules.py))
+in that a `CommitRule` is only applied once on an entire commit while a `LineRule` is applied for every line in the commit
+(you can also apply it once to the title using a `target` - see the examples section below).
The benefit of a commit rule is that it allows commit rules to implement more complex checks that span multiple lines and/or checks
that should only be done once per commit.
-While every ```LineRule``` can be implemented as a ```CommitRule```, it's usually easier and more concise to go with a ```LineRule``` if
+While every `LineRule` can be implemented as a `CommitRule`, it's usually easier and more concise to go with a `LineRule` if
that fits your needs.
-## Examples ##
+### Examples
-In terms of code, writing your own ```CommitRule``` or ```LineRule``` is very similar.
-The only 2 differences between a ```CommitRule``` and a ```LineRule``` are the parameters of the ```validate(...)``` method and the extra
-```target``` attribute that ```LineRule``` requires.
+In terms of code, writing your own `CommitRule` or `LineRule` is very similar.
+The only 2 differences between a `CommitRule` and a `LineRule` are the parameters of the `validate(...)` method and the extra
+`target` attribute that `LineRule` requires.
-Consider the following ```CommitRule``` that can be found in [examples/my_commit_rules.py](https://github.com/jorisroovers/gitlint/blob/master/examples/my_commit_rules.py):
+Consider the following `CommitRule` that can be found in [examples/my_commit_rules.py](https://github.com/jorisroovers/gitlint/blob/main/examples/my_commit_rules.py):
```python
+# -*- coding: utf-8 -*-
from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
@@ -104,18 +108,21 @@ class SignedOffBy(CommitRule):
id = "UC2"
def validate(self, commit):
+ self.log.debug("SignedOffBy: This will be visible when running `gitlint --debug`")
+
for line in commit.message.body:
if line.startswith("Signed-Off-By"):
- return []
+ return
- msg = "Body does not contain a 'Signed-Off-By Line'"
+ msg = "Body does not contain a 'Signed-Off-By' line"
return [RuleViolation(self.id, msg, line_nr=1)]
```
-Note the use of the ```name``` and ```id``` class attributes and the ```validate(...)``` method taking a single ```commit``` parameter.
+Note the use of the `name` and `id` class attributes and the `validate(...)` method taking a single `commit` parameter.
-Contrast this with the following ```LineRule``` that can be found in [examples/my_line_rules.py](https://github.com/jorisroovers/gitlint/blob/master/examples/my_line_rules.py):
+Contrast this with the following `LineRule` that can be found in [examples/my_line_rules.py](https://github.com/jorisroovers/gitlint/blob/main/examples/my_line_rules.py):
```python
+# -*- coding: utf-8 -*-
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle
from gitlint.options import ListOption
@@ -138,33 +145,37 @@ class SpecialChars(LineRule):
options_spec = [ListOption('special-chars', ['$', '^', '%', '@', '!', '*', '(', ')'],
"Comma separated list of characters that should not occur in the title")]
- def validate(self, line, commit):
+ def validate(self, line, _commit):
+ self.log.debug("SpecialChars: This will be visible when running `gitlint --debug`")
+
violations = []
- # option values can be accessed via self.options
+ # options can be accessed by looking them up by their name in self.options
for char in self.options['special-chars'].value:
if char in line:
- violation = RuleViolation(self.id, "Title contains the special character '{}'".format(char), line)
+ msg = "Title contains the special character '{0}'".format(char)
+ violation = RuleViolation(self.id, msg, line)
violations.append(violation)
return violations
+
```
Note the following 2 differences:
-- **extra ```target``` class attribute**: in this example set to ```CommitMessageTitle``` indicating that this ```LineRule```
-should only be applied once to the commit message title. The alternative value for ```target``` is ```CommitMessageBody```,
+- **extra `target` class attribute**: in this example set to `CommitMessageTitle` indicating that this `LineRule`
+should only be applied once to the commit message title. The alternative value for `target` is `CommitMessageBody`,
in which case gitlint will apply
your rule to **every** line in the commit message body.
-- **```validate(...)``` takes 2 parameters**: Line rules get the ```line``` against which they are applied as the first parameter and
-the ```commit``` object of which the line is part of as second.
+- **`validate(...)` takes 2 parameters**: Line rules get the `line` against which they are applied as the first parameter and
+the `commit` object of which the line is part of as second.
-In addition, you probably also noticed the extra ```options_spec``` class attribute which allows you to make your rules configurable.
-Options are not unique to ```LineRule```s, they can also be used by ```CommitRule```s and are further explained in the
+In addition, you probably also noticed the extra `options_spec` class attribute which allows you to make your rules configurable.
+Options are not unique to `LineRule`s, they can also be used by `CommitRule`s and are further explained in the
[Options](user_defined_rules.md#options) section below.
-# The commit object ##
-Both ```CommitRule```s and ```LineRule```s take a ```commit``` object in their ```validate(...)``` methods.
+## The commit object
+Both `CommitRule`s and `LineRule`s take a `commit` object in their `validate(...)` methods.
The table below outlines the various attributes of that commit object that can be used during validation.
@@ -175,14 +186,14 @@ commit.message.original | string | Original commit message as ret
commit.message.full | string | Full commit message, with comments (lines starting with #) removed.
commit.message.title | string | Title/subject of the commit message: the first line
commit.message.body | string[] | List of lines in the body of the commit message (i.e. starting from the second line)
-commit.author_name | string | Name of the author, result of ```git log --pretty=%aN```
-commit.author_email | string | Email of the author, result of ```git log --pretty=%aE```
-commit.date | datetime | Python ```datetime``` object representing the time of commit
+commit.author_name | string | Name of the author, result of `git log --pretty=%aN`
+commit.author_email | string | Email of the author, result of `git log --pretty=%aE`
+commit.date | datetime | Python `datetime` object representing the time of commit
commit.is_merge_commit | boolean | Boolean indicating whether the commit is a merge commit or not.
commit.is_revert_commit | boolean | Boolean indicating whether the commit is a revert commit or not.
commit.is_fixup_commit | boolean | Boolean indicating whether the commit is a fixup commit or not.
commit.is_squash_commit | boolean | Boolean indicating whether the commit is a squash commit or not.
-commit.parents | string[] | List of parent commit ```sha```s (only for merge commits).
+commit.parents | string[] | List of parent commit `sha`s (only for merge commits).
commit.changed_files | string[] | List of files changed in the commit (relative paths).
commit.branches | string[] | List of branch names the commit is part of
commit.context | object | Object pointing to the bigger git context that the commit is part of
@@ -190,17 +201,17 @@ commit.context.current_branch | string | Name of the currently active b
commit.context.repository_path | string | Absolute path pointing to the git repository being linted
commit.context.commits | object[] | List of commits gitlint is acting on, NOT all commits in the repo.
-# Violations ##
-In order to let gitlint know that there is a violation in the commit being linted, users should have the ```validate(...)```
-method in their rules return a list of ```RuleViolation```s.
+## Violations
+In order to let gitlint know that there is a violation in the commit being linted, users should have the `validate(...)`
+method in their rules return a list of `RuleViolation`s.
!!! important
- The ```validate(...)``` method doesn't always need to return a list, you can just skip the return statement in case there are no violations.
+ The `validate(...)` method doesn't always need to return a list, you can just skip the return statement in case there are no violations.
However, in case of a single violation, validate should return a **list** with a single item.
-The ```RuleViolation``` class has the following generic signature:
+The `RuleViolation` class has the following generic signature:
-```
+```python
RuleViolation(rule_id, message, content=None, line_nr=None):
```
With the parameters meaning the following:
@@ -210,9 +221,9 @@ Parameter | Type | Description
rule_id | string | Rule's unique string id
message | string | Short description of the violation
content | string | (optional) the violating part of commit or line
-line_nr | int | (optional) line number in the commit message where the violation occurs. **Automatically set to the correct line number for ```LineRule```s if not set explicitly.**
+line_nr | int | (optional) line number in the commit message where the violation occurs. **Automatically set to the correct line number for `LineRule`s if not set explicitly.**
-A typical ```validate(...)``` implementation for a ```CommitRule``` would then be as follows:
+A typical `validate(...)` implementation for a `CommitRule` would then be as follows:
```python
def validate(self, commit)
for line_nr, line in commit.message.body:
@@ -222,16 +233,17 @@ def validate(self, commit)
return []
```
-The parameters of this ```RuleViolation``` can be directly mapped onto gitlint's output as follows:
+The parameters of this `RuleViolation` can be directly mapped onto gitlint's output as follows:
![How Rule violations map to gitlint output](images/RuleViolation.png)
-# Options ##
+## Options
-In order to make your own rules configurable, you can add an optional ```options_spec``` attribute to your rule class
-(supported for both ```LineRule``` and ```CommitRule```).
+In order to make your own rules configurable, you can add an optional `options_spec` attribute to your rule class
+(supported for both `LineRule` and `CommitRule`).
```python
+# -*- coding: utf-8 -*-
from gitlint.rules import CommitRule, RuleViolation
from gitlint.options import IntOption
@@ -256,57 +268,143 @@ class BodyMaxLineCount(CommitRule):
```
-By using ```options_spec```, you make your option available to be configured through a ```.gitlint``` file
+By using `options_spec`, you make your option available to be configured through a `.gitlint` file
or one of the [other ways to configure gitlint](configuration.md). Gitlint automatically takes care of the parsing and input validation.
-For example, to change the value of the ```max-line-count``` option, add the following to your ```.gitlint``` file:
+For example, to change the value of the `max-line-count` option, add the following to your `.gitlint` file:
```ini
[body-max-line-count]
body-max-line-count=1
```
-As ```options_spec``` is a list, you can obviously have multiple options per rule. The general signature of an option is:
-```Option(name, default_value, description)```.
+As `options_spec` is a list, you can obviously have multiple options per rule. The general signature of an option is:
+`Option(name, default_value, description)`.
-Gitlint supports a variety of different option types, all can be imported from ```gitlint.options```:
+Gitlint supports a variety of different option types, all can be imported from `gitlint.options`:
-Option Class | Use for
-----------------|--------------
-StrOption | Strings
-IntOption | Integers. ```IntOption``` takes an optional ```allow_negative``` parameter if you want to allow negative integers.
-BoolOption | Booleans. Valid values: `true`, `false`. Case-insensitive.
-ListOption | List of strings. Comma separated.
-PathOption | Directory or file path. Takes an optional ```type``` parameter for specifying path type (```file```, ```dir``` (=default) or ```both```).
+Option Class | Use for
+------------------|--------------
+`StrOption ` | Strings
+`IntOption` | Integers. `IntOption` takes an optional `allow_negative` parameter if you want to allow negative integers.
+`BoolOption` | Booleans. Valid values: `true`, `false`. Case-insensitive.
+`ListOption` | List of strings. Comma separated.
+`PathOption` | Directory or file path. Takes an optional `type` parameter for specifying path type (`file`, `dir` (=default) or `both`).
+`RegexOption` | String representing a [Python-style regex](https://docs.python.org/library/re.html) - compiled and validated before rules are applied.
!!! note
Gitlint currently does not support options for all possible types (e.g. float, list of int, etc).
[We could use a hand getting those implemented](contributing.md)!
-# Rule requirements ##
+## Configuration Rules
+
+_Introduced in gitlint v0.14.0_
+
+Configuration rules are special rules that are applied once per commit and *BEFORE* any other rules are run.
+Configuration rules are meant to dynamically change gitlint's configuration and/or the commit that is about to be
+linted.
+A typically use-case for this is when you want to modifying gitlint's behavior for all rules against a commit matching
+specific circumstances.
+
+!!! warning
+ Configuration rules can drastically change the way gitlint behaves and are typically only needed for more advanced
+ use-cases. We recommend you double check:
+
+ 1. Whether gitlint already supports your use-case out-of-the-box (special call-out for [ignore rules](rules.md#i1-ignore-by-title) which allow you to ignore (parts) of your commit message).
+ 2. Whether there's a [Contrib Rule](contrib_rules.md) that implements your use-case.
+ 3. Whether you can implement your use-case using a regular Commit or Line user-defined rule (see above).
+
+
+As with other user-defined rules, the easiest way to get started is by copying [`my_configuration.py` from the examples directory](https://github.com/jorisroovers/gitlint/tree/main/examples/my_configuration_rules.py) and modifying it to fit your need.
+
+```python
+# -*- coding: utf-8 -*-
+from gitlint.rules import ConfigurationRule
+from gitlint.options import IntOption
+
+class ReleaseConfigurationRule(ConfigurationRule):
+ """
+ This rule will modify gitlint's behavior for Release Commits.
+
+ This example might not be the most realistic for a real-world scenario,
+ but is meant to give an overview of what's possible.
+ """
+
+ # A rule MUST have a human friendly name
+ name = "release-configuration-rule"
+
+ # A rule MUST have a *unique* id, we recommend starting with UCR
+ # (for User-defined Configuration-Rule), but this can really be anything.
+ id = "UCR1"
+
+ # A rule MAY have an option_spec if its behavior should be configurable.
+ options_spec = [IntOption('custom-verbosity', 2, "Gitlint verbosity for release commits")]
+
+ def apply(self, config, commit):
+ self.log.debug("ReleaseConfigurationRule: This will be visible when running `gitlint --debug`")
+
+ # If the commit title starts with 'Release', we want to modify
+ # how all subsequent rules interpret that commit
+ if commit.message.title.startswith("Release"):
+
+ # If your Release commit messages are auto-generated, the
+ # body might contain trailing whitespace. Let's ignore that
+ config.ignore.append("body-trailing-whitespace")
+
+ # Similarly, the body lines might exceed 80 chars,
+ # let's set gitlint's limit to 200
+ # To set rule options use:
+ # config.set_rule_option(<rule-name>, <rule-option>, <value>)
+ config.set_rule_option("body-max-line-length", "line-length", 200)
+
+ # For kicks, let's set gitlint's verbosity to 2
+ # To set general options use
+ # config.set_general_option(<general-option>, <value>)
+ config.set_general_option("verbosity", 2)
+ # We can also use custom options to make this configurable
+ config.set_general_option("verbosity", self.options['custom-verbosity'].value)
+
+ # Strip any lines starting with $ from the commit message
+ # (this only affects how gitlint sees your commit message, it does
+ # NOT modify your actual commit in git)
+ commit.message.body = [line for line in commit.message.body if not line.startswith("$")]
+
+ # You can add any extra properties you want to the commit object,
+ # these will be available later on in all rules.
+ commit.my_property = u"This is my property"
+```
+
+For all available properties and methods on the `config` object, have a look at the
+[LintConfig class](https://github.com/jorisroovers/gitlint/blob/main/gitlint/config.py). Please do not use any
+properties or methods starting with an underscore, as those are subject to change.
+
+
+## Rule requirements
As long as you stick with simple rules that are similar to the sample user-defined rules (see the
-[examples](https://github.com/jorisroovers/gitlint/blob/master/examples/my_commit_rules.py) directory), gitlint
+[examples](https://github.com/jorisroovers/gitlint/blob/main/examples/my_commit_rules.py) directory), gitlint
should be able to discover and execute them. While clearly you can run any python code you want in your rules,
you might run into some issues if you don't follow the conventions that gitlint requires.
-While the [rule finding source-code](https://github.com/jorisroovers/gitlint/blob/master/gitlint/rule_finder.py) is the
+While the [rule finding source-code](https://github.com/jorisroovers/gitlint/blob/main/gitlint/rule_finder.py) is the
ultimate source of truth, here are some of the requirements that gitlint enforces.
-## Rule class requirements ###
+### Rule class requirements
-- Rules **must** extend from ```LineRule``` or ```CommitRule```
-- Rule classes **must** have ```id``` and ```name``` string attributes. The ```options_spec``` is optional,
+- Rules **must** extend from `LineRule`, `CommitRule` or `ConfigurationRule`
+- Rule classes **must** have `id` and `name` string attributes. The `options_spec` is optional,
but if set, it **must** be a list of gitlint Options.
-- Rule classes **must** have a ```validate``` method. In case of a ```CommitRule```, ```validate``` **must** take a single ```commit``` parameter.
- In case of ```LineRule```, ```validate``` **must** take ```line``` and ```commit``` as first and second parameters.
-- LineRule classes **must** have a ```target``` class attributes that is set to either ```CommitMessageTitle``` or ```CommitMessageBody```.
-- User Rule id's **cannot** start with ```R```, ```T```, ```B``` or ```M``` as these rule ids are reserved for gitlint itself.
-- Rules **should** have a case-insensitive unique id as only one rule can exist with a given id. While gitlint does not enforce this, having multiple rules with
- the same id might lead to unexpected or undeterministic behavior.
-
-## extra-path requirements ###
-- If ```extra-path``` is a directory, it does **not** need to be a proper python package, i.e. it doesn't require an ```__init__.py``` file.
-- Python files containing user-defined rules must have a ```.py``` extension. Files with a different extension will be ignored.
-- The ```extra-path``` will be searched non-recursively, i.e. all rule classes must be present at the top level ```extra-path``` directory.
-- User rule classes must be defined in the modules that are part of ```extra-path```, rules that are imported from outside the ```extra-path``` will be ignored.
+- `CommitRule` and `LineRule` classes **must** have a `validate` method.
+- In case of a `CommitRule`, `validate` **must** take a single `commit` parameter.
+- In case of `LineRule`, `validate` **must** take `line` and `commit` as first and second parameters.
+- `ConfigurationRule` classes **must** have an `apply` method that take `config` and `commit` as first and second parameters.
+- LineRule classes **must** have a `target` class attributes that is set to either `CommitMessageTitle` or `CommitMessageBody`.
+- User Rule id's **cannot** start with `R`, `T`, `B`, `M` or `I` as these rule ids are reserved for gitlint itself.
+- Rules **should** have a case-insensitive unique id as only one rule can exist with a given id. While gitlint does not
+ enforce this, having multiple rules with the same id might lead to unexpected or undeterministic behavior.
+
+### extra-path requirements
+- If `extra-path` is a directory, it does **not** need to be a proper python package, i.e. it doesn't require an `__init__.py` file.
+- Python files containing user-defined rules must have a `.py` extension. Files with a different extension will be ignored.
+- The `extra-path` will be searched non-recursively, i.e. all rule classes must be present at the top level `extra-path` directory.
+- User rule classes must be defined in the modules that are part of `extra-path`, rules that are imported from outside the `extra-path` will be ignored.