lint: Rely on core gitlint skipping of revert commits.

gitlint 0.13.0 and above skip revert commits[1].  This obviates the
need for a custom rule.

[1] https://jorisroovers.com/gitlint/configuration/#ignore-revert-commits
This commit is contained in:
Alex Vandiver 2021-02-23 14:21:45 -08:00
parent 174fa0a331
commit 12ade4c49d
3 changed files with 3 additions and 26 deletions

View File

@ -3,7 +3,7 @@ ignore=title-trailing-punctuation, body-min-length, body-is-missing, title-imper
extra-path=tools/lib/gitlint-rules.py extra-path=tools/lib/gitlint-rules.py
[title-match-regex-allow-exception] [title-match-regex]
regex=^(.+:\ )?[A-Z].+\.$ regex=^(.+:\ )?[A-Z].+\.$
[title-max-length] [title-max-length]

View File

@ -45,7 +45,7 @@ pyinotify
tblib tblib
# Needed to lint Git commit messages # Needed to lint Git commit messages
gitlint gitlint>=0.13.0
# Needed for visualising cprofile reports # Needed for visualising cprofile reports
snakeviz snakeviz

View File

@ -1,8 +1,6 @@
import re
from typing import List from typing import List
from gitlint.git import GitCommit from gitlint.git import GitCommit
from gitlint.options import StrOption
from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation
# Word list from https://github.com/m1foley/fit-commit # Word list from https://github.com/m1foley/fit-commit
@ -307,31 +305,10 @@ class ImperativeMood(LineRule):
violation = RuleViolation( violation = RuleViolation(
self.id, self.id,
self.error_msg.format( self.error_msg.format(
word=first_word, word=first_word, imperative=imperative, title=commit.message.title,
imperative=imperative,
title=commit.message.title,
), ),
) )
violations.append(violation) violations.append(violation)
return violations return violations
class TitleMatchRegexAllowException(LineRule):
"""Allows revert commits contrary to the built-in title-match-regex rule"""
name = "title-match-regex-allow-exception"
id = "Z2"
target = CommitMessageTitle
options_spec = [StrOption("regex", ".*", "Regex the title should match")]
def validate(self, title: str, commit: GitCommit) -> List[RuleViolation]:
regex = self.options["regex"].value
pattern = re.compile(regex, re.UNICODE)
if not pattern.search(title) and not title.startswith('Revert "'):
violation_msg = f"Title does not match regex ({regex})"
return [RuleViolation(self.id, violation_msg, title)]
return []