Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ golangci:
- gochecknoinits # 1
- revive # 1
- path: ^rules/shortsubject/shortsubject\.go$
linters: # 7 findings
- mnd # 2
linters: # 5 findings
- revive # 2
- gochecknoglobals # 1
- gochecknoinits # 1
Expand Down
12 changes: 10 additions & 2 deletions rules/shortsubject/shortsubject.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"github.com/forkcloser/git-validation/validate"
)

// The two lengths of a subject, in characters: it must be strictly shorter
// than limit, and is better kept within preferred. The description and the
// messages name them too.
const (
limit = 90
preferred = 72
)

// ShortSubjectRule is the rule being registered.
var ShortSubjectRule = validate.Rule{
Name: "short-subject",
Expand All @@ -34,15 +42,15 @@ func ValidateShortSubject(r validate.Rule, c git.CommitEntry) (vr validate.Resul
// them; in bytes, 85 accented characters failed the rule.
length := utf8.RuneCountInString(c["subject"])

if length >= 90 {
if length >= limit {
vr.Pass = false
vr.Msg = "commit subject exceeds 90 characters"

return vr
}

vr.Pass = true
if length > 72 {
if length > preferred {
vr.Msg = "commit subject is under 90 characters, but is still more than 72 chars"
} else {
vr.Msg = "commit subject is 72 characters or less! *yay*"
Expand Down
Loading