Skip to content

Commit ae97971

Browse files
tristan-googlenashif
authored andcommitted
gitlint: Add "commit" to violation messages
This PR clarifies the violation messages emitted by gitlint when checking the commit message. For example: * Before: `43: UC4 Line exceeds max length (N>75): "..."` * After: `43: UC4 Commit line exceeds max length (N>75): "..."` This makes it easier to identify the source of the error since there is currently no additional context besides the error code UC*. I recently pushed a commit that had some sample code as part of the commit body that exceeded the lenght limit, and thought the error was referring to one of my source files based on the line it showed. (feel free to laugh at me, but let's make it better for the next person) Signed-off-by: Tristan Honscheid <[email protected]>
1 parent dfc97f3 commit ae97971

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

scripts/gitlint/zephyr_commit_rules.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def validate(self, commit):
3232
line_count = len(filtered)
3333
min_line_count = self.options['min-line-count'].value
3434
if line_count < min_line_count:
35-
message = "Body has no content, should at least have {} line.".format(min_line_count)
35+
message = "Commit body has no content, should at least have {} line(s).".format(min_line_count)
3636
return [RuleViolation(self.id, message, line_nr=1)]
3737

3838
class BodyMaxLineCount(CommitRule):
@@ -49,7 +49,7 @@ def validate(self, commit):
4949
line_count = len(commit.message.body)
5050
max_line_count = self.options['max-line-count'].value
5151
if line_count > max_line_count:
52-
message = "Body contains too many lines ({0} > {1})".format(line_count, max_line_count)
52+
message = "Commit body contains too many lines ({0} > {1})".format(line_count, max_line_count)
5353
return [RuleViolation(self.id, message, line_nr=1)]
5454

5555
class SignedOffBy(CommitRule):
@@ -72,14 +72,14 @@ def validate(self, commit):
7272
return [RuleViolation(self.id, "Signed-off-by: must have a full name", line_nr=1)]
7373
else:
7474
return
75-
return [RuleViolation(self.id, "Body does not contain a 'Signed-off-by:' line", line_nr=1)]
75+
return [RuleViolation(self.id, "Commit body does not contain a 'Signed-off-by:' line", line_nr=1)]
7676

7777
class TitleMaxLengthRevert(LineRule):
7878
name = "title-max-length-no-revert"
7979
id = "UC5"
8080
target = CommitMessageTitle
8181
options_spec = [IntOption('line-length', 72, "Max line length")]
82-
violation_message = "Title exceeds max length ({0}>{1})"
82+
violation_message = "Commit title exceeds max length ({0}>{1})"
8383

8484
def validate(self, line, _commit):
8585
max_length = self.options['line-length'].value
@@ -95,7 +95,7 @@ class TitleStartsWithSubsystem(LineRule):
9595
def validate(self, title, _commit):
9696
regex = self.options['regex'].value
9797
pattern = re.compile(regex, re.UNICODE)
98-
violation_message = "Title does not follow [subsystem]: [subject] (and should not start with literal subsys:)"
98+
violation_message = "Commit title does not follow [subsystem]: [subject] (and should not start with literal subsys:)"
9999
if not pattern.search(title):
100100
return [RuleViolation(self.id, violation_message, title)]
101101

@@ -104,7 +104,7 @@ class MaxLineLengthExceptions(LineRule):
104104
id = "UC4"
105105
target = CommitMessageBody
106106
options_spec = [IntOption('line-length', 80, "Max line length")]
107-
violation_message = "Line exceeds max length ({0}>{1})"
107+
violation_message = "Commit body line exceeds max length ({0}>{1})"
108108

109109
def validate(self, line, _commit):
110110
max_length = self.options['line-length'].value
@@ -128,5 +128,5 @@ def validate(self, line, _commit):
128128
flags = re.IGNORECASE
129129
for tag in self.tags:
130130
if re.search(rf"^\s*{tag}:", line, flags=flags):
131-
return [RuleViolation(self.id, f"Body contains a blocked tag: {tag}")]
131+
return [RuleViolation(self.id, f"Commit body contains a blocked tag: {tag}")]
132132
return

0 commit comments

Comments
 (0)