1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
# pylint: disable=too-few-public-methods
###############################################################################
# Copyright (C) Intel Corporation
#
# SPDX-License-Identifier: MIT
###############################################################################
"""
Custom rules for gitlint
"""
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle
class TitleCapitalized(LineRule):
"""This rule will enforce that the first word of the commit message title is
capitalized"""
name = "title-is-capitalized"
id = "UL3"
target = CommitMessageTitle
def validate(self, line, _commit):
"""Validate that the title is capitalized"""
violations = []
if line:
if not line[0].isupper():
violation = RuleViolation(
self.id, "Title does not start with a capital letter",
line)
violations.append(violation)
return violations
class TitleImperative(LineRule):
"""This rule will enforce that the commit message title uses the imperative
mood.
For now rather than using an advanced linguistic database, it just rejects
common bad patterns, such as words ending in ed or ing."""
name = "title-is-imperative"
id = "UL5"
target = CommitMessageTitle
def validate(self, line, _commit):
"""Validate that the title is imperative"""
violations = []
bad_suffixes = ('ed', 'ing')
for word in line.split():
if word.endswith(bad_suffixes):
violation = RuleViolation(self.id, "Title is not imperative",
line)
violations.append(violation)
break
return violations
|