User Defined Rules¶
Gitlint supports the concept of user-defined rules: the ability for users to write their own custom rules in python.
To use this, set the extra-path
option to point to a directory where gitlint will search
for python files containing user-defined rule classes.
[general]
extra-path=tools/gitlint/myrules # (1)
# Alternatively, point to a specific file
[general]
extra-path=tools/gitlint/myrules/my_rules.py
- This path is relative to the current working directory in which you're executing gitlint.
gitlint --extra-path "tools/gitlint/myrules" # (1)
# Alternatively, point to a specific file
gitlint --extra-path "tools/gitlint/myrules/my_rules.py"
# You can also use -c style config flags
gitlint -c general.extra-path=tools/gitlint/myrules
- This path is relative to the current working directory in which you're executing gitlint.
Example using the examples
directory in the gitlint source code:
$ cat examples/commit-message-1 | gitlint --extra-path examples/
1: UC2 Body does not contain a 'Signed-off-by Line' # (1)
- Example output of a user-defined Signed-off-by rule. Other violations occuring in examples/commit-message-1 were removed for brevity.
The SignedOffBy
user-defined CommitRule
was discovered by gitlint when it discovered
examples/gitlint/my_commit_rules.py
If you want to check whether your rules are properly discovered by gitlint, you can use the --debug
flag:
$ gitlint --debug --extra-path examples/
# [output cut for brevity]
UC1: body-max-line-count
body-max-line-count=3
UC2: body-requires-signed-off-by
UL1: title-no-special-chars
special-chars=['$', '^', '%', '@', '!', '*', '(', ')']
Tip
In most cases it's really the easiest to just copy an example from the examples directory and modify it to your needs.