Skip to content

Commit 6907bf5

Browse files
committed
title-min-length: Update tests, add docs
* Update tests related to the `title-min-length` (mostly cosmetic changes) * Add one more test for empty title. * Add the new `title-min-length` rule to various documentation files. Signed-off-by: mr.Shu <mr@shu.io>
1 parent 83ad30f commit 6907bf5

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

docs/configuration.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ extra-path=examples/
6868
[title-max-length]
6969
line-length=80
7070

71+
# Conversely, you can also enforce minimal length of a title with the
72+
# "title-min-length" rule:
73+
# [title-min-length]
74+
# min-length=5
75+
7176
[title-must-not-contain-word]
7277
# Comma-separated list of words that should not occur in the title. Matching is case
7378
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
@@ -429,4 +434,4 @@ gitlint -c general.staged=true # different way of doing the same
429434
#.gitlint
430435
[general]
431436
staged=true
432-
```
437+
```

docs/rules.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ T4 | title-hard-tab | >= 0.1.0 | Title cannot contain h
1414
T5 | title-must-not-contain-word | >= 0.1.0 | Title cannot contain certain words (default: "WIP")
1515
T6 | title-leading-whitespace | >= 0.4.0 | Title cannot have leading whitespace (space or tab)
1616
T7 | title-match-regex | >= 0.5.0 | Title must match a given regex (default: .*)
17+
T8 | title-max-length | >= | Title length must be &gt; 5 chars.
1718
B1 | body-max-line-length | >= 0.1.0 | Lines in the body must be &lt; 80 chars
1819
B2 | body-trailing-whitespace | >= 0.1.0 | Body cannot have trailing whitespace (space or tab)
1920
B3 | body-hard-tab | >= 0.1.0 | Body cannot contain hard tab characters (\t)
@@ -82,6 +83,12 @@ ID | Name | gitlint version | Description
8283
------|-----------------------------|-----------------|-------------------------------------------
8384
T7 | title-match-regex | >= 0.5 | Title must match a given regex (default: .*)
8485

86+
## T8: title-min-length ##
87+
88+
ID | Name | gitlint version | Description
89+
------|-----------------------------|-----------------|-------------------------------------------
90+
T1 | title-min-length | >= | Title length must be &gt; 5 chars.
91+
8592

8693
### Options ###
8794

@@ -240,4 +247,4 @@ ignore=all
240247
[ignore-by-body]
241248
regex=(.*)release(.*)
242249
ignore=T1,body-min-length,B6
243-
```
250+
```

gitlint/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class LintConfig(object):
5151
rules.TitleHardTab,
5252
rules.TitleMustNotContainWord,
5353
rules.TitleRegexMatches,
54+
rules.TitleMinLength,
5455
rules.BodyMaxLineLength,
5556
rules.BodyMinLength,
5657
rules.BodyMissing,

gitlint/files/gitlint

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
# [title-max-length]
4444
# line-length=50
4545

46+
# Conversely, you can also enforce minimal length of a title with the
47+
# "title-min-length" rule:
48+
# [title-min-length]
49+
# min-length=5
50+
4651
# [title-must-not-contain-word]
4752
# Comma-separated list of words that should not occur in the title. Matching is case
4853
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
@@ -103,4 +108,4 @@
103108
# under [general] section above.
104109
# [contrib-title-conventional-commits]
105110
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
106-
# types = bugfix,user-story,epic
111+
# types = bugfix,user-story,epic

gitlint/rules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class TitleMinLength(LineRule):
245245
def validate(self, title, _commit):
246246
min_length = self.options['min-length'].value
247247
actual_length = len(title)
248-
if 0 < actual_length < min_length:
248+
if actual_length < min_length:
249249
violation_message = "Title is too short ({0}<{1})".format(actual_length, min_length)
250250
return [RuleViolation(self.id, violation_message, title, 1)]
251251

gitlint/tests/rules/test_title_rules.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_min_line_length(self):
160160
violation = rule.validate(u"å" * 72, None)
161161
self.assertIsNone(violation)
162162

163-
# assert error on line length > 72
163+
# assert error on line length < 5
164164
expected_violation = RuleViolation("T8", "Title is too short (4<5)", u"å" * 4, 1)
165165
violations = rule.validate(u"å" * 4, None)
166166
self.assertListEqual(violations, [expected_violation])
@@ -174,3 +174,8 @@ def test_min_line_length(self):
174174
expected_violation = RuleViolation("T8", "Title is too short (2<3)", u"å" * 2, 1)
175175
violations = rule.validate(u"å" * 2, None)
176176
self.assertListEqual(violations, [expected_violation])
177+
178+
# assert raise on empty title
179+
expected_violation = RuleViolation("T8", "Title is too short (0<3)", "", 1)
180+
violations = rule.validate("", None)
181+
self.assertListEqual(violations, [expected_violation])

0 commit comments

Comments
 (0)