summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoris Roovers <joris.roovers@gmail.com>2019-06-17 16:48:25 +0200
committerJoris Roovers <joris.roovers@gmail.com>2019-06-17 22:50:38 +0200
commit07738b3bd34f91977888a954f95527411babae1c (patch)
tree7501b832f981351d3608afb6a53912428b0fcc7b
parentd3bd68ccf42f24dacd40709eeac954c54ccaf331 (diff)
Docs for Contrib Rules
- Documented Contrib Rules: how to use them, how to write them Additional minor changes: - Renamed the ConventionalCommit id from CL1 to CT1 to align with existing conventions of using a 'T' for title rules. - Help output now wrapped at 120 chars instead of 80
-rw-r--r--CHANGELOG.md11
-rw-r--r--docs/configuration.md54
-rw-r--r--docs/contrib_rules.md71
-rw-r--r--docs/contributing.md34
-rw-r--r--docs/index.md27
-rw-r--r--docs/rules.md38
-rw-r--r--gitlint/cli.py3
-rw-r--r--gitlint/contrib/rules/conventional_commit.py6
-rw-r--r--gitlint/contrib/rules/signedoff_by.py2
-rw-r--r--gitlint/files/gitlint10
-rw-r--r--gitlint/tests/config/test_config.py4
-rw-r--r--gitlint/tests/contrib/test_contrib_rules.py9
-rw-r--r--gitlint/tests/contrib/test_conventional_commit.py8
-rw-r--r--gitlint/tests/expected/test_cli/test_contrib_14
-rw-r--r--mkdocs.yml1
-rw-r--r--qa/expected/test_contrib/test_contrib_rules_14
-rw-r--r--qa/expected/test_contrib/test_contrib_rules_with_config_14
17 files changed, 219 insertions, 71 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f1effbb..b7d983d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog #
+## v0.12.0 (In Progress) ##
+
+- [Contrib Rules](http://jorisroovers.github.io/gitlint/contrib_rules): community-contributed rules that are disabled
+ by default, but can be enabled through configuration. Contrib rules are meant to augment default gitlint behavior by
+ providing users with rules for common use-cases without forcing these rules on all gitlint users.
+ interested in contributing new rules
+ - **New Contrib Rule**: ```contrib-title-conventional-commits``` enforces the [Conventional Commits](https://www.conventionalcommits.org) spec. Details in our [documentation](http://jorisroovers.github.io/gitlint/contrib_rules/#ct1-contrib-title-conventional-commits).
+ - **New Contrib Rule**: ```cc1-contrib-requires-signed-off-by``` ensures that all commit messages contain a ```Sign-Off-By``` line. Details in our [documentation](http://jorisroovers.github.io/gitlint/contrib_rules/#cc1-contrib-requires-signed-off-by).
+ - If you're interested in adding new Contrib rules to gitlint, please start by reading the
+ [Contributing](http://jorisroovers.github.io/gitlint/contributing/) page. Thanks for considering!
+
## v0.11.0 (2019-03-13) ##
- Python 3.7 support
diff --git a/docs/configuration.md b/docs/configuration.md
index 9c9197c..6c830af 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -1,3 +1,6 @@
+# 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.
@@ -36,6 +39,10 @@ The block below shows a sample ```.gitlint``` file. Details about rule config op
# Enable debug mode (prints more output). Disabled by default.
# debug=true
+# Enable community contributed rules
+# See http://jorisroovers.github.io/gitlint/contrib_rules for details
+# contrib=contrib-title-conventional-commits,CC1
+
# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
# extra-path=examples/
@@ -79,7 +86,29 @@ The block below shows a sample ```.gitlint``` file. Details about rule config op
# 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
-# regex = "[^@]+@foo.com"
+# regex=[^@]+@foo.com
+
+# [ignore-by-title]
+# Ignore certain rules for commits of which the title matches a regex
+# E.g. Match commit titles that start with "Release"
+# regex=^Release(.*)
+#
+# Ignore certain rules, you can reference them by their id or by their full name
+# Use 'all' to ignore all rules
+# ignore=T1,body-min-length
+
+# [ignore-by-body]
+# Ignore certain rules for commits of which the body has a line that matches a regex
+# E.g. Match bodies that have a line that that contain "release"
+# regex=(.*)release(.*)
+#
+# Ignore certain rules, you can reference them by their id or by their full name
+# Use 'all' to ignore all rules
+# ignore=T1,body-min-length
+
+# [contrib-title-conventional-commits]
+# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
+# types = bugfix,user-story,epic
```
# Commandline config #
@@ -120,14 +149,15 @@ gitlint configuration is applied in the following order of precedence:
The table below outlines 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.
-Name | Default value | gitlint version | commandline flag | Description
-----------------------|---------------|------------------|---------------------------------------|-------------------------------------
-silent | false | >= 0.1 | ```--silent``` | Enable silent mode (no output). Use [exit](index.md#exit-codes) code to determine result.
-verbosity | 3 | >= 0.1 | ```--verbosity=3``` | Amount of output gitlint will show when printing errors.
-ignore-merge-commits | true | >= 0.7.0 | Not available | Whether or not to ignore merge commits.
-ignore-fixup-commits | true | >= 0.9.0 | Not available | Whether or not to ignore [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits.
-ignore-squash-commits | true | >= 0.9.0 | Not available | Whether or not to ignore [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) commits.
-ignore | [] (=empty) | >= 0.1 | ```--ignore=T1,body-min-length``` | Comma seperated list of rules to ignore (by name or id)
-debug | false | >= 0.7.1 | ```--debug``` | Enable debugging output
-target | (empty) | >= 0.8.0 | ```---target=/home/joe/myrepo/ ``` | Target git repository gitlint should be linting against.
-extra-path | (empty) | >= 0.8.0 | ```---extra-path=/home/joe/rules/``` | Path where gitlint looks for [user-defined rules](user_defined_rules.md).
+Name | Default value | gitlint version | commandline flag | Description
+----------------------|---------------|------------------|--------------------------------------------------------|-------------------------------------
+silent | false | >= 0.1.0 | ```--silent``` | Enable silent mode (no output). Use [exit](index.md#exit-codes) code to determine result.
+verbosity | 3 | >= 0.1.0 | ```--verbose=3``` | Amount of output gitlint will show when printing errors.
+ignore-merge-commits | true | >= 0.7.0 | Not available | Whether or not to ignore merge commits.
+ignore-fixup-commits | true | >= 0.9.0 | Not available | Whether or not to ignore [fixup](https://git-scm.com/docs/git-commit#git-commit---fixupltcommitgt) commits.
+ignore-squash-commits | true | >= 0.9.0 | Not available | Whether or not to ignore [squash](https://git-scm.com/docs/git-commit#git-commit---squashltcommitgt) commits.
+ignore | [] (=empty) | >= 0.1.0 | ```--ignore=T1,body-min-length``` | Comma seperated list of rules to ignore (by name or id)
+debug | false | >= 0.7.1 | ```--debug``` | Enable debugging output
+target | (empty) | >= 0.8.0 | ```--target=/home/joe/myrepo/ ``` | Target git repository gitlint should be linting against.
+extra-path | (empty) | >= 0.8.0 | ```--extra-path=/home/joe/rules/``` | Path where gitlint looks for [user-defined rules](user_defined_rules.md).
+contrib | (empty) | >= 0.12.0 | ```--contrib=contrib-title-conventional-commits,CC1``` | [Contrib rules](contrib_rules) to enable.
diff --git a/docs/contrib_rules.md b/docs/contrib_rules.md
new file mode 100644
index 0000000..63c6467
--- /dev/null
+++ b/docs/contrib_rules.md
@@ -0,0 +1,71 @@
+# Using Contrib Rules
+_Introduced in gitlint v0.12.0_
+
+Contrib rules are community-**contrib**uted rules that are disabled by default, but can be enabled through configuration.
+
+Contrib rules are meant to augment default gitlint behavior by providing users with rules for common use-cases without
+forcing these rules on all gitlint users. In addition, Contrib rules enable re-usability so 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.
+```sh
+$ cat examples/commit-message-1 | gitlint --contrib contrib-title-conventional-commits,CC1
+1: CC1 Body does not contain a 'Signed-Off-By' line
+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."
+
+# These are the default violations
+1: T3 Title has trailing punctuation (.): "WIP: This is the title of a commit message."
+1: T5 Title contains the word 'WIP' (case-insensitive): "WIP: This is the title of a commit message."
+2: B4 Second line is not empty: "The second line should typically be empty"
+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:
+
+```ini
+[general]
+contrib=contrib-title-conventional-commits,CC1
+
+[contrib-title-conventional-commits]
+# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
+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
+
+ID | Name | gitlint version | Description
+------|-------------------------------------|------------------ |-------------------------------------------
+CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [Conventional Commits](https://www.conventionalcommits.org/) commit message style on the title.
+CC1 | contrib-requires-signed-off-by | >= 0.12.0 | Commit body must contain a `Signed-Off-By` line.
+
+## CT1: contrib-title-conventional-commits ##
+
+ID | Name | gitlint version | Description
+------|---------------------------------------|--------------------|-------------------------------------------
+CT1 | contrib-title-conventional-commits | >= 0.12.0 | Enforces [Conventional Commits](https://www.conventionalcommits.org/) commit message style on the title.
+
+### Options ###
+
+Name | gitlint version | Default | Description
+---------------|--------------------|--------------|----------------------------------
+types | >= 0.12.0 | `fix,feat,chore,docs,style,refactor,perf,test` | Comma separated list of allowed commit types.
+
+
+## CC1: contrib-requires-signed-off-by ##
+
+ID | Name | gitlint version | Description
+------|---------------------------------------|--------------------|-------------------------------------------
+CT1 | 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.
+
+### Options ###
+
+Name | gitlint version | Default | Description
+---------------|--------------------|--------------|----------------------------------
+types | >= 0.12.0 | `fix,feat,chore,docs,style,refactor,perf,test` | Comma separated list of allowed commit types.
+
+
+
+# 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
diff --git a/docs/contributing.md b/docs/contributing.md
index a412ac0..ddb79a5 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -1,8 +1,9 @@
# Contributing
We'd love for you to contribute to gitlint. Thanks for your interest!
-Sometimes it takes a while for [me](https://github.com/jorisroovers) to get back to you (sometimes up to a few months,
-this is a hobby project), but rest assured that we read your message and appreciate your interest!
+Often it takes a while for us (well, actually just [me](https://github.com/jorisroovers)) to get back to you
+(sometimes up to a few months, this is a hobby project), but rest assured that we read your message and appreciate
+your interest!
We maintain a [wishlist on our wiki](https://github.com/jorisroovers/gitlint/wiki/Wishlist),
but we're obviously open to any suggestions!
@@ -21,6 +22,7 @@ When contributing code, please consider all the parts that are typically require
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 #
There is a Vagrantfile in this repository that can be used for development.
@@ -82,3 +84,31 @@ mkdocs serve
Then access the documentation website on your host machine on [http://localhost:8000]().
Note that this is only supported for python >= 2.7.
+
+# 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!
+
+Before starting, please read all the other documentation on this page about contributing first. 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.
+
+
+## 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 less formal spec, here's what gitlint requires of Contrib rules.
+
+- Since Contrib rules are really just user-defined rules that live withing the gitlint code-base, all the [user-rule requirements](user_defined_rules/#rule-requirements) also apply to Contrib rules.
+- All contrib rules **must** have associated unit tests. We *sort of* enforce this by a unit test that verifies that there's a
+ test file for each contrib file.
+- All contrib rules **must** have names that start with `contrib-`. This is to easily distinguish them from default gitlint rules.
+- All contrib rule ids **must** start with `CT` (for LineRules targeting the title), `CB` (for LineRules targeting the body) or `CC` (for CommitRules). Again, this is to easily distinguish them from default gitlint rules.
+- All contrib rules **must** have unique names and ids.
+- You **can** add multiple rule classes to the same file, but classes **should** be logically grouped together in a single file that implements related rules.
+- Contrib rules **should** be meaningfully different from one another. If a behavior change or tweak can be added to an existing rule by adding options, that should be considered first. However, large [god classes](https://en.wikipedia.org/wiki/God_object) that implement multiple rules in a single class should obviously also be avoided.
+- Contrib rules **should** use [options](user_defined_rules/#options) to make rules configurable. \ No newline at end of file
diff --git a/docs/index.md b/docs/index.md
index 36f39e0..a0b8046 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -15,15 +15,15 @@ Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or
## Features ##
- **Commit message hook**: [Auto-trigger validations against new commit message right when you're committing](#using-gitlint-as-a-commit-msg-hook).
- - **Easily integrated**: Gitlint will validate any git commit message you give it via standard input.
- Perfect for [integration with your own scripts or CI system](#using-gitlint-in-a-ci-environment).
+ - **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
[well-known](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html),
[community](http://addamhardy.com/blog/2013/06/05/good-commit-messages-and-enforcing-them-with-git-hooks/),
[standards](http://chris.beams.io/posts/git-commit/), others are based on checks that we've found
useful throughout the years.
- **Easily configurable:** Gitlint has sane defaults, but [you can also easily customize it to your own liking](configuration.md).
- - **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).
+ - **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.3+ and PyPy2.
- **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: high unit test coverage, integration tests,
@@ -96,21 +96,17 @@ Usage: gitlint [OPTIONS] COMMAND [ARGS]...
Git lint tool, checks your git commit messages for styling issues
Options:
- --target DIRECTORY Path of the target git repository. [default:
- current working directory]
+ --target DIRECTORY Path of the target git repository. [default: current working directory]
-C, --config PATH Config file location [default: .gitlint]
- -c TEXT Config flags in format <rule>.<option>=<value>
- (e.g.: -c T1.line-length=80). Flag can be used
- multiple times to set multiple config values.
+ -c TEXT Config flags in format <rule>.<option>=<value> (e.g.: -c T1.line-length=80). Flag can be
+ used multiple times to set multiple config values.
--commits TEXT The range of commits to lint. [default: HEAD]
- -e, --extra-path PATH Path to a directory or python module with extra
- user-defined rules
+ -e, --extra-path PATH Path to a directory or python module with extra user-defined rules
--ignore TEXT Ignore rules (comma-separated by id or name).
- --msg-filename FILENAME Path to a file containing a commit-msg
- -v, --verbose Verbosity, more v's for more verbose output (e.g.:
- -v, -vv, -vvv). [default: -vvv]
- -s, --silent Silent mode (no output). Takes precedence over -v,
- -vv, -vvv.
+ --contrib TEXT Contrib rules to enable (comma-separated by id or name).
+ --msg-filename FILENAME Path to a file containing a commit-msg.
+ -v, --verbose Verbosity, more v's for more verbose output (e.g.: -v, -vv, -vvv). [default: -vvv]
+ -s, --silent Silent mode (no output). Takes precedence over -v, -vv, -vvv.
-d, --debug Enable debugging output.
--version Show the version and exit.
--help Show this message and exit.
@@ -274,6 +270,7 @@ ignore=all
Right now it's not possible to write user-defined ignore rules to handle more complex user-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).
+
## 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.
diff --git a/docs/rules.md b/docs/rules.md
index 9142337..d84da22 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -5,25 +5,25 @@ Note that you can also [write your own user-defined rule](user_defined_rules.md)
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
-------|-----------------------------|---------------- |-------------------------------------------
-T1 | title-max-length | >= 0.1 | Title length must be &lt; 72 chars.
-T2 | title-trailing-whitespace | >= 0.1 | Title cannot have trailing whitespace (space or tab)
-T3 | title-trailing-punctuation | >= 0.1 | Title cannot have trailing punctuation (?:!.,;)
-T4 | title-hard-tab | >= 0.1 | Title cannot contain hard tab characters (\t)
-T5 | title-must-not-contain-word | >= 0.1 | Title cannot contain certain words (default: "WIP")
-T6 | title-leading-whitespace | >= 0.4 | Title cannot have leading whitespace (space or tab)
-T7 | title-match-regex | >= 0.5 | Title must match a given regex (default: .*)
-B1 | body-max-line-length | >= 0.1 | Lines in the body must be &lt; 80 chars
-B2 | body-trailing-whitespace | >= 0.1 | Body cannot have trailing whitespace (space or tab)
-B3 | body-hard-tab | >= 0.1 | Body cannot contain hard tab characters (\t)
-B4 | body-first-line-empty | >= 0.1 | First line of the body (second line of commit message) must be empty
-B5 | body-min-length | >= 0.4 | Body length must be at least 20 characters
-B6 | body-is-missing | >= 0.4 | Body message must be specified
-B7 | body-changed-file-mention | >= 0.4 | Body must contain references to certain files if those files are changed in the last commit
-M1 | author-valid-email | >= 0.9 | Author email address must be a valid email address
-
-
+ID | Name | gitlint version | Description
+------|-----------------------------|-------------------|-------------------------------------------
+T1 | title-max-length | >= 0.1.0 | Title length must be &lt; 72 chars.
+T2 | title-trailing-whitespace | >= 0.1.0 | Title cannot have trailing whitespace (space or tab)
+T3 | title-trailing-punctuation | >= 0.1.0 | Title cannot have trailing punctuation (?:!.,;)
+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: .*)
+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)
+B4 | body-first-line-empty | >= 0.1.0 | First line of the body (second line of commit message) must be empty
+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
+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
## T1: title-max-length ##
diff --git a/gitlint/cli.py b/gitlint/cli.py
index cdaa60f..1e07978 100644
--- a/gitlint/cli.py
+++ b/gitlint/cli.py
@@ -129,7 +129,8 @@ def get_stdin_data():
return False
-@click.group(invoke_without_command=True, epilog="When no COMMAND is specified, gitlint defaults to 'gitlint lint'.")
+@click.group(invoke_without_command=True, context_settings={'max_content_width': 120},
+ epilog="When no COMMAND is specified, gitlint defaults to 'gitlint lint'.")
@click.option('--target', type=click.Path(exists=True, resolve_path=True, file_okay=False, readable=True),
help="Path of the target git repository. [default: current working directory]")
@click.option('-C', '--config', type=click.Path(exists=True, dir_okay=False, readable=True, resolve_path=True),
diff --git a/gitlint/contrib/rules/conventional_commit.py b/gitlint/contrib/rules/conventional_commit.py
index 912843c..26367c4 100644
--- a/gitlint/contrib/rules/conventional_commit.py
+++ b/gitlint/contrib/rules/conventional_commit.py
@@ -8,17 +8,17 @@ RULE_REGEX = re.compile(r"[^(]+?(\([^)]+?\))?: .+")
class ConventionalCommit(LineRule):
- """This rule enforces the spec at https://www.conventionalcommits.org/."""
+ """ This rule enforces the spec at https://www.conventionalcommits.org/. """
name = "contrib-title-conventional-commits"
- id = "CL1"
+ id = "CT1"
target = CommitMessageTitle
options_spec = [
ListOption(
"types",
["fix", "feat", "chore", "docs", "style", "refactor", "perf", "test"],
- "Comma seperated list of allowed commit types.",
+ "Comma separated list of allowed commit types.",
)
]
diff --git a/gitlint/contrib/rules/signedoff_by.py b/gitlint/contrib/rules/signedoff_by.py
index a5025e5..c2034e7 100644
--- a/gitlint/contrib/rules/signedoff_by.py
+++ b/gitlint/contrib/rules/signedoff_by.py
@@ -3,7 +3,7 @@ from gitlint.rules import CommitRule, RuleViolation
class SignedOffBy(CommitRule):
- """ This rule will enforce that each commit contains a "Signed-Off-By" line.
+ """ This rule will enforce that each commit body contains a "Signed-Off-By" line.
We keep things simple here and just check whether the commit body contains a line that starts with "Signed-Off-By".
"""
diff --git a/gitlint/files/gitlint b/gitlint/files/gitlint
index 69f1503..44ed23e 100644
--- a/gitlint/files/gitlint
+++ b/gitlint/files/gitlint
@@ -18,6 +18,10 @@
# Enable debug mode (prints more output). Disabled by default.
# debug=true
+# Enable community contributed rules
+# See http://jorisroovers.github.io/gitlint/contrib_rules for details
+# contrib=contrib-title-conventional-commits,CC1
+
# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
# extra-path=examples/
@@ -79,4 +83,8 @@
#
# Ignore certain rules, you can reference them by their id or by their full name
# Use 'all' to ignore all rules
-# ignore=T1,body-min-length \ No newline at end of file
+# ignore=T1,body-min-length
+
+# [contrib-title-conventional-commits]
+# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
+# types = bugfix,user-story,epic \ No newline at end of file
diff --git a/gitlint/tests/config/test_config.py b/gitlint/tests/config/test_config.py
index 05c49d8..d7f1d63 100644
--- a/gitlint/tests/config/test_config.py
+++ b/gitlint/tests/config/test_config.py
@@ -120,14 +120,14 @@ class LintConfigTests(BaseTestCase):
self.assertTrue(actual_rule.is_contrib)
self.assertEqual(ustr(type(actual_rule)), "<class 'conventional_commit.ConventionalCommit'>")
- self.assertEqual(actual_rule.id, 'CL1')
+ self.assertEqual(actual_rule.id, 'CT1')
self.assertEqual(actual_rule.name, u'contrib-title-conventional-commits')
self.assertEqual(actual_rule.target, rules.CommitMessageTitle)
expected_rule_option = options.ListOption(
"types",
["fix", "feat", "chore", "docs", "style", "refactor", "perf", "test"],
- "Comma seperated list of allowed commit types.",
+ "Comma separated list of allowed commit types.",
)
self.assertListEqual(actual_rule.options_spec, [expected_rule_option])
diff --git a/gitlint/tests/contrib/test_contrib_rules.py b/gitlint/tests/contrib/test_contrib_rules.py
index dfb3fab..3fa4048 100644
--- a/gitlint/tests/contrib/test_contrib_rules.py
+++ b/gitlint/tests/contrib/test_contrib_rules.py
@@ -44,11 +44,10 @@ class ContribRuleTests(BaseTestCase):
# Contrib line rules id's start with "CL"
if issubclass(clazz, rules.LineRule):
- self.assertTrue(clazz.id.startswith("CL"))
-
- # Contrib commit rule id's start with "CC"
- if issubclass(clazz, rules.CommitRule):
- self.assertTrue(clazz.id.startswith("CC"))
+ if clazz.target == rules.CommitMessageTitle:
+ self.assertTrue(clazz.id.startswith("CT"))
+ elif clazz.target == rules.CommitMessageBody:
+ self.assertTrue(clazz.id.startswith("CB"))
def test_contrib_rule_uniqueness(self):
""" Tests that all contrib rules have unique identifiers.
diff --git a/gitlint/tests/contrib/test_conventional_commit.py b/gitlint/tests/contrib/test_conventional_commit.py
index 64d39ae..df4b798 100644
--- a/gitlint/tests/contrib/test_conventional_commit.py
+++ b/gitlint/tests/contrib/test_conventional_commit.py
@@ -10,7 +10,7 @@ class ContribConventionalCommitTests(BaseTestCase):
def test_enable(self):
# Test that rule can be enabled in config
- for rule_ref in ['CL1', 'contrib-title-conventional-commits']:
+ for rule_ref in ['CT1', 'contrib-title-conventional-commits']:
config = LintConfig()
config.contrib = [rule_ref]
self.assertIn(ConventionalCommit(), config.rules)
@@ -24,13 +24,13 @@ class ContribConventionalCommitTests(BaseTestCase):
self.assertListEqual([], violations)
# assert violation on wrong type
- expected_violation = RuleViolation("CL1", "Title does not start with one of fix, feat, chore, docs,"
+ expected_violation = RuleViolation("CT1", "Title does not start with one of fix, feat, chore, docs,"
" style, refactor, perf, test", u"bår: foo")
violations = rule.validate(u"bår: foo", None)
self.assertListEqual([expected_violation], violations)
# assert violation on wrong format
- expected_violation = RuleViolation("CL1", "Title does not follow ConventionalCommits.org format "
+ expected_violation = RuleViolation("CT1", "Title does not follow ConventionalCommits.org format "
"'type(optional-scope): description'", u"fix föo")
violations = rule.validate(u"fix föo", None)
self.assertListEqual([expected_violation], violations)
@@ -43,5 +43,5 @@ class ContribConventionalCommitTests(BaseTestCase):
# assert violation when using incorrect type when types have been reconfigured
violations = rule.validate(u"fix: hür dur", None)
- expected_violation = RuleViolation("CL1", u"Title does not start with one of föo, bär", u"fix: hür dur")
+ expected_violation = RuleViolation("CT1", u"Title does not start with one of föo, bär", u"fix: hür dur")
self.assertListEqual([expected_violation], violations)
diff --git a/gitlint/tests/expected/test_cli/test_contrib_1 b/gitlint/tests/expected/test_cli/test_contrib_1
index 7bb0836..c578fcd 100644
--- a/gitlint/tests/expected/test_cli/test_contrib_1
+++ b/gitlint/tests/expected/test_cli/test_contrib_1
@@ -1,3 +1,3 @@
1: CC1 Body does not contain a 'Signed-Off-By' line
-1: CL1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test: "Test tïtle"
-1: CL1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "Test tïtle"
+1: CT1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test: "Test tïtle"
+1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "Test tïtle"
diff --git a/mkdocs.yml b/mkdocs.yml
index cff7ad1..8796cfc 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -6,6 +6,7 @@ pages:
- Home: index.md
- Configuration: configuration.md
- Rules: rules.md
+ - Contrib Rules: contrib_rules.md
- User Defined Rules: user_defined_rules.md
- Contributing: contributing.md
diff --git a/qa/expected/test_contrib/test_contrib_rules_1 b/qa/expected/test_contrib/test_contrib_rules_1
index a4c3918..a8e4bfc 100644
--- a/qa/expected/test_contrib/test_contrib_rules_1
+++ b/qa/expected/test_contrib/test_contrib_rules_1
@@ -1,4 +1,4 @@
1: CC1 Body does not contain a 'Signed-Off-By' line
-1: CL1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test: "WIP Thi$ is å title"
-1: CL1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "WIP Thi$ is å title"
+1: CT1 Title does not start with one of fix, feat, chore, docs, style, refactor, perf, test: "WIP Thi$ is å title"
+1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "WIP Thi$ is å title"
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP Thi$ is å title"
diff --git a/qa/expected/test_contrib/test_contrib_rules_with_config_1 b/qa/expected/test_contrib/test_contrib_rules_with_config_1
index dfc5fcb..21d467a 100644
--- a/qa/expected/test_contrib/test_contrib_rules_with_config_1
+++ b/qa/expected/test_contrib/test_contrib_rules_with_config_1
@@ -1,4 +1,4 @@
1: CC1 Body does not contain a 'Signed-Off-By' line
-1: CL1 Title does not start with one of föo, bår: "WIP Thi$ is å title"
-1: CL1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "WIP Thi$ is å title"
+1: CT1 Title does not start with one of föo, bår: "WIP Thi$ is å title"
+1: CT1 Title does not follow ConventionalCommits.org format 'type(optional-scope): description': "WIP Thi$ is å title"
1: T5 Title contains the word 'WIP' (case-insensitive): "WIP Thi$ is å title"