Rule Options
In order to make your own rules configurable, you can add an optional options_spec
attribute to your rule class.
By using options_spec
, gitlint automatically takes care of the parsing and input validation.
You can configure your option like so:
Because options_spec
is a list, you can have multiple options per rule.
options_spec = [
IntOption("max-lint-count", 3, "Maximum body line count"),
BoolOption("count-signoff-by", True, "Include 'Sign-off By' lines in count"),
# etc
]
Option Types¶
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 ). |
RegexOption |
String representing a Python-style regex - 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!
Examples¶
options_spec = [
StrOption("my-str-option", "default", "Fancy string option"),
IntOption("my-int-option", 3, "Fancy integer option", allow_negative=True),
BoolOption("my-bool-option", False, "Fancy boolean option"),
ListOption("my-list-option"), ["foo", "bar"], "Fancy list option"
PathOption("my-regex-option", "/foo/bar", "Fancy path option", type="dir"),
RegexOption("my-regex-option", "^(foo|bar)", "Fancy regex option"),
]