Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 37faae2

Browse files
committedMar 6, 2022
refactor(lint): add Description, Infos to Issue
1 parent e09d206 commit 37faae2

26 files changed

+162
-145
lines changed
 

‎formatter/default.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ func (f *DefaultFormatter) writeIssues(w *strings.Builder, sign, title string, i
6363
func (f *DefaultFormatter) writeIssue(w *strings.Builder, sign string, issue *lint.Issue) {
6464
space := " "
6565

66-
// ❌ rule-name:
67-
// - message1
68-
// - message2
66+
// ❌ rule-name: description
67+
// - info1
68+
// - info2
6969

70-
fmt.Fprintf(w, "\n%s %s:", space+sign, issue.Name())
71-
for _, msg := range issue.Message() {
70+
fmt.Fprintf(w, "\n%s %s: %s", space+sign, issue.RuleName(), issue.Description())
71+
for _, msg := range issue.Infos() {
7272
fmt.Fprintf(w, "\n%s - %s", space+space, msg)
7373
}
7474
}

‎formatter/json.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func (f *JSONFormatter) Format(result *lint.Result) (string, error) {
1919
output := make(map[string]interface{}, 4)
2020

2121
output["input"] = result.Input()
22-
output["valid"] = result.IsOK()
2322
output["issues"] = f.formatIssue(result.Issues())
2423

2524
formatted, err := json.Marshal(output)
@@ -35,11 +34,12 @@ func (f *JSONFormatter) formatIssue(issues []*lint.Issue) []interface{} {
3534
for _, issue := range issues {
3635
output := make(map[string]interface{})
3736

38-
output["name"] = issue.Name()
37+
output["name"] = issue.RuleName()
3938
output["severity"] = issue.Severity()
39+
output["description"] = issue.Description()
4040

41-
if len(issue.Message()) > 0 {
42-
output["messages"] = issue.Message()
41+
if len(issue.Infos()) > 0 {
42+
output["infos"] = issue.Infos()
4343
}
4444

4545
formattedIssues = append(formattedIssues, output)

‎internal/cmd/lint.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ func runLint(confFilePath, fileInput string) (lintResult string, hasError bool,
4646
return "", false, err
4747
}
4848

49-
res, err := linter.Lint(commitMsg)
49+
result, err := linter.Lint(commitMsg)
5050
if err != nil {
5151
return "", false, err
5252
}
5353

54-
resStr, err := format.Format(res)
54+
output, err := format.Format(result)
5555
if err != nil {
5656
return "", false, err
5757
}
58-
return resStr, hasErrorSeverity(res), nil
58+
return output, hasErrorSeverity(result), nil
5959
}
6060

6161
func getLinter(confParam string) (*lint.Linter, lint.Formatter, error) {
@@ -136,9 +136,9 @@ func readStdInPipe() (string, error) {
136136
return strings.TrimSpace(s), nil
137137
}
138138

139-
func hasErrorSeverity(res *lint.Result) bool {
140-
for _, r := range res.Issues() {
141-
if r.Severity() == lint.SeverityError {
139+
func hasErrorSeverity(result *lint.Result) bool {
140+
for _, i := range result.Issues() {
141+
if i.Severity() == lint.SeverityError {
142142
return true
143143
}
144144
}

‎lint/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ type Rule interface {
6666
// Validate validates the rule for given commit message
6767
// if given commit is valid, return true and messages slice are ignored
6868
// if invalid, return a error messages with false
69-
Validate(msg Commit) (messages []string, isValid bool)
69+
Validate(msg Commit) (issue *Issue, isValid bool)
7070
}

‎lint/linter.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,42 @@ func New(conf *Config, rules []Rule) (*Linter, error) {
2323
func (l *Linter) Lint(commitMsg string) (*Result, error) {
2424
msg, err := l.parser.Parse(commitMsg)
2525
if err != nil {
26-
return l.parserErrorRule(commitMsg, err)
26+
issues := l.parserErrorRule(commitMsg, err)
27+
return newResult(commitMsg, issues...), nil
2728
}
2829
return l.LintCommit(msg)
2930
}
3031

3132
// LintCommit checks the given Commit against rules
3233
func (l *Linter) LintCommit(msg Commit) (*Result, error) {
33-
res := newResult(msg.Message())
34+
issues := make([]*Issue, 0, len(l.rules))
3435

3536
for _, rule := range l.rules {
3637
currentRule := rule
3738
severity := l.conf.GetSeverity(currentRule.Name())
38-
ruleRes, isValid := l.runRule(currentRule, severity, msg)
39+
issue, isValid := l.runRule(currentRule, severity, msg)
3940
if !isValid {
40-
res.add(ruleRes)
41+
issues = append(issues, issue)
4142
}
4243
}
4344

44-
return res, nil
45+
return newResult(msg.Message(), issues...), nil
4546
}
4647

4748
func (l *Linter) runRule(rule Rule, severity Severity, msg Commit) (*Issue, bool) {
48-
failMsgs, isOK := rule.Validate(msg)
49-
if isOK {
49+
issue, isValid := rule.Validate(msg)
50+
if isValid {
5051
return nil, true
5152
}
52-
res := newIssue(rule.Name(), failMsgs, severity)
53-
return res, false
54-
}
55-
56-
func (l *Linter) parserErrorRule(commitMsg string, err error) (*Result, error) {
57-
res := newResult(commitMsg)
5853

59-
errMsg := err.Error()
60-
61-
ruleFail := newIssue("parser", []string{errMsg}, SeverityError)
62-
res.add(ruleFail)
54+
issue.ruleName = rule.Name()
55+
issue.severity = severity
56+
return issue, false
57+
}
6358

64-
return res, nil
59+
func (l *Linter) parserErrorRule(commitMsg string, err error) []*Issue {
60+
issue := NewIssue(err.Error())
61+
issue.ruleName = "parser"
62+
issue.severity = SeverityError
63+
return []*Issue{issue}
6564
}

‎lint/result.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,51 @@
11
package lint
22

3-
// Result holds Result of linter
3+
// Result holds a linter result
44
type Result struct {
5-
inputMsg string
6-
5+
input string
76
issues []*Issue
87
}
98

10-
func newResult(inputMsg string) *Result {
9+
func newResult(input string, issues ...*Issue) *Result {
1110
return &Result{
12-
inputMsg: inputMsg,
11+
input: input,
12+
issues: issues,
1313
}
1414
}
1515

16-
// AddError adds
17-
func (res *Result) add(r *Issue) {
18-
res.issues = append(res.issues, r)
19-
}
20-
21-
// IsOK returns true if commit message passed all the rules
22-
func (res *Result) IsOK() bool { return len(res.issues) == 0 }
23-
24-
// Input returns input commit message
25-
func (res *Result) Input() string { return res.inputMsg }
16+
// Input returns the input commit message
17+
func (r *Result) Input() string { return r.input }
2618

27-
// Issues returns rule Issues
28-
func (res *Result) Issues() []*Issue { return res.issues }
19+
// Issues returns linter issues
20+
func (r *Result) Issues() []*Issue { return r.issues }
2921

30-
// Issue holds Failure of a linter rule
22+
// Issue holds a rule result
3123
type Issue struct {
32-
name string
24+
ruleName string
25+
3326
severity Severity
34-
messages []string
27+
28+
description string
29+
30+
additionalInfos []string
3531
}
3632

37-
func newIssue(name string, msgs []string, severity Severity) *Issue {
33+
// NewIssue returns a new issue
34+
func NewIssue(desc string, infos ...string) *Issue {
3835
return &Issue{
39-
name: name,
40-
messages: msgs,
41-
severity: severity,
36+
description: desc,
37+
additionalInfos: infos,
4238
}
4339
}
4440

45-
// Name returns rule name
46-
func (r *Issue) Name() string { return r.name }
41+
// RuleName returns rule name
42+
func (r *Issue) RuleName() string { return r.ruleName }
4743

4844
// Severity returns severity of the Rule Failure
4945
func (r *Issue) Severity() Severity { return r.severity }
5046

51-
// Message returns the error messages of failed rule
52-
func (r *Issue) Message() []string { return r.messages }
47+
// Description returns description of the issue
48+
func (r *Issue) Description() string { return r.description }
49+
50+
// Infos returns additional infos about the issue
51+
func (r *Issue) Infos() []string { return r.additionalInfos }

‎rule/body_max_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *BodyMaxLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates BodyMaxLenRule
25-
func (r *BodyMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLen(r.CheckLen, msg.Body())
25+
func (r *BodyMaxLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLen("body", r.CheckLen, msg.Body())
2727
}

‎rule/body_max_line_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ func (r *BodyMaxLineLenRule) Apply(setting lint.RuleSetting) error {
2424
}
2525

2626
// Validate validates BodyMaxLineLenRule rule
27-
func (r *BodyMaxLineLenRule) Validate(msg lint.Commit) ([]string, bool) {
28-
return checkMaxLineLength(r.CheckLen, msg.Body())
27+
func (r *BodyMaxLineLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
28+
return validateMaxLineLength("body", r.CheckLen, msg.Body())
2929
}

‎rule/body_min_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *BodyMinLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates BodyMinLenRule
25-
func (r *BodyMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMinLen(r.CheckLen, msg.Body())
25+
func (r *BodyMinLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMinLen("body", r.CheckLen, msg.Body())
2727
}

‎rule/desc_max_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *DescriptionMaxLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates DescriptionMaxLenRule
25-
func (r *DescriptionMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLen(r.CheckLen, msg.Description())
25+
func (r *DescriptionMaxLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLen("description", r.CheckLen, msg.Description())
2727
}

‎rule/desc_min_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *DescriptionMinLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates DescriptionMinLenRule
25-
func (r *DescriptionMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMinLen(r.CheckLen, msg.Description())
25+
func (r *DescriptionMinLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMinLen("description", r.CheckLen, msg.Description())
2727
}

‎rule/footer_enum.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rule
33
import (
44
"fmt"
55
"sort"
6+
"strings"
67

78
"github.com/conventionalcommit/commitlint/lint"
89
)
@@ -29,20 +30,21 @@ func (r *FooterEnumRule) Apply(setting lint.RuleSetting) error {
2930
}
3031

3132
// Validate validates FooterEnumRule
32-
func (r *FooterEnumRule) Validate(msg lint.Commit) ([]string, bool) {
33-
msgs := []string{}
33+
func (r *FooterEnumRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
34+
var invalids []string
3435

3536
for _, note := range msg.Notes() {
3637
isFound := search(r.Tokens, note.Token())
3738
if !isFound {
38-
errMsg := fmt.Sprintf("footer token '%s' is not allowed, you can use one of %v", note.Token(), r.Tokens)
39-
msgs = append(msgs, errMsg)
39+
invalids = append(invalids, note.Token())
4040
}
4141
}
4242

43-
if len(msgs) == 0 {
43+
if len(invalids) == 0 {
4444
return nil, true
4545
}
4646

47-
return msgs, false
47+
desc := fmt.Sprintf("you can use one of %v", r.Tokens)
48+
info := fmt.Sprintf("[%s] tokens are not allowed", strings.Join(invalids, ", "))
49+
return lint.NewIssue(desc, info), false
4850
}

‎rule/footer_max_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *FooterMaxLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates FooterMaxLenRule
25-
func (r *FooterMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLen(r.CheckLen, msg.Footer())
25+
func (r *FooterMaxLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLen("footer", r.CheckLen, msg.Footer())
2727
}

‎rule/footer_max_line_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *FooterMaxLineLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates FooterMaxLineLenRule rule
25-
func (r *FooterMaxLineLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLineLength(r.CheckLen, msg.Footer())
25+
func (r *FooterMaxLineLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLineLength("footer", r.CheckLen, msg.Footer())
2727
}

‎rule/footer_min_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *FooterMinLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates FooterMinLenRule
25-
func (r *FooterMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMinLen(r.CheckLen, msg.Footer())
25+
func (r *FooterMinLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMinLen("footer", r.CheckLen, msg.Footer())
2727
}

‎rule/header_max_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *HeadMaxLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates HeadMaxLenRule
25-
func (r *HeadMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLen(r.CheckLen, msg.Header())
25+
func (r *HeadMaxLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLen("header", r.CheckLen, msg.Header())
2727
}

‎rule/header_min_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ func (r *HeadMinLenRule) Apply(setting lint.RuleSetting) error {
2424
}
2525

2626
// Validate validates HeadMinLenRule
27-
func (r *HeadMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
28-
return checkMinLen(r.CheckLen, msg.Header())
27+
func (r *HeadMinLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
28+
return validateMinLen("header", r.CheckLen, msg.Header())
2929
}

‎rule/rule.go

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"sort"
77
"strings"
8+
9+
"github.com/conventionalcommit/commitlint/lint"
810
)
911

1012
func errInvalidArg(ruleName string, err error) error {
@@ -15,66 +17,80 @@ func errInvalidFlag(ruleName, flagName string, err error) error {
1517
return fmt.Errorf("%s: invalid flag '%s': %v", ruleName, flagName, err)
1618
}
1719

18-
func checkCharset(charset, toCheck string) (string, bool) {
20+
func formMinLenMsg(typ string, actualLen, expectedLen int) string {
21+
return fmt.Sprintf("%s length is %d, should have atleast %d chars", typ, actualLen, expectedLen)
22+
}
23+
24+
func formMaxLenDesc(typ string, actualLen, expectedLen int) string {
25+
return fmt.Sprintf("%s length is %d, should have less than %d chars", typ, actualLen, expectedLen)
26+
}
27+
28+
func formMaxLineLenDesc(typ string, expectedLen int) string {
29+
return fmt.Sprintf("each %s line should have less than %d chars", typ, expectedLen)
30+
}
31+
32+
func search(arr []string, toFind string) bool {
33+
ind := sort.Search(len(arr), func(i int) bool {
34+
return arr[i] >= toFind
35+
})
36+
return ind < len(arr) && arr[ind] == toFind
37+
}
38+
39+
func validateCharset(allowedCharset, toCheck string) (string, bool) {
1940
invalidRunes := ""
2041
for _, ch := range toCheck {
21-
if !strings.ContainsRune(charset, ch) {
42+
if !strings.ContainsRune(allowedCharset, ch) {
2243
invalidRunes += string(ch)
2344
}
2445
}
2546

2647
if invalidRunes == "" {
2748
return "", true
2849
}
29-
3050
return invalidRunes, false
3151
}
3252

33-
func search(arr []string, toFind string) bool {
34-
ind := sort.Search(len(arr), func(i int) bool {
35-
return arr[i] >= toFind
36-
})
37-
return ind < len(arr) && arr[ind] == toFind
53+
func validateMinLen(typ string, expectedLen int, toCheck string) (*lint.Issue, bool) {
54+
actualLen := len(toCheck)
55+
if actualLen >= expectedLen {
56+
return nil, true
57+
}
58+
59+
desc := formMinLenMsg(typ, actualLen, expectedLen)
60+
return lint.NewIssue(desc), false
3861
}
3962

40-
func checkMaxLen(checkLen int, toCheck string) ([]string, bool) {
41-
if checkLen < 0 {
63+
func validateMaxLen(typ string, expectedLen int, toCheck string) (*lint.Issue, bool) {
64+
if expectedLen < 0 {
4265
return nil, true
4366
}
4467

45-
if len(toCheck) <= checkLen {
68+
if len(toCheck) <= expectedLen {
4669
return nil, true
4770
}
4871

49-
errMsg := fmt.Sprintf("length is %d, should have less than %d chars", len(toCheck), checkLen)
50-
return []string{errMsg}, false
72+
desc := formMaxLenDesc(typ, len(toCheck), expectedLen)
73+
return lint.NewIssue(desc), false
5174
}
5275

53-
func checkMaxLineLength(checkLen int, toCheck string) ([]string, bool) {
76+
func validateMaxLineLength(typ string, expectedLen int, toCheck string) (*lint.Issue, bool) {
5477
lines := strings.Split(toCheck, "\n")
5578

5679
msgs := []string{}
5780
for index, line := range lines {
5881
actualLen := len(line)
59-
if actualLen > checkLen {
60-
errMsg := fmt.Sprintf("in line %d, length is %d, should have less than %d chars", index+1, actualLen, checkLen)
82+
if actualLen > expectedLen {
83+
errMsg := fmt.Sprintf("in line %d, length is %d", index+1, actualLen)
6184
msgs = append(msgs, errMsg)
6285
}
6386
}
6487

6588
if len(msgs) == 0 {
6689
return nil, true
6790
}
68-
return msgs, false
69-
}
7091

71-
func checkMinLen(checkLen int, toCheck string) ([]string, bool) {
72-
actualLen := len(toCheck)
73-
if actualLen >= checkLen {
74-
return nil, true
75-
}
76-
errMsg := fmt.Sprintf("length is %d, should have atleast %d chars", actualLen, checkLen)
77-
return []string{errMsg}, false
92+
desc := formMaxLineLenDesc(typ, expectedLen)
93+
return lint.NewIssue(desc, msgs...), false
7894
}
7995

8096
func setBoolArg(retVal *bool, arg interface{}) error {
@@ -151,6 +167,7 @@ func toStringArr(arg interface{}) ([]string, error) {
151167
return strArr, nil
152168
case []string:
153169
return argVal, nil
170+
default:
171+
return nil, fmt.Errorf("expects array of string value, but got %#v", arg)
154172
}
155-
return nil, fmt.Errorf("expects array of string value, but got %#v", arg)
156173
}

‎rule/scope_charset.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package rule
22

33
import (
4-
"fmt"
5-
64
"github.com/conventionalcommit/commitlint/lint"
75
)
86

@@ -26,12 +24,13 @@ func (r *ScopeCharsetRule) Apply(setting lint.RuleSetting) error {
2624
}
2725

2826
// Validate validates ScopeCharsetRule
29-
func (r *ScopeCharsetRule) Validate(msg lint.Commit) ([]string, bool) {
30-
invalidChars, isValid := checkCharset(r.Charset, msg.Scope())
27+
func (r *ScopeCharsetRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
28+
invalidChars, isValid := validateCharset(r.Charset, msg.Scope())
3129
if isValid {
3230
return nil, true
3331
}
3432

35-
errMsg := fmt.Sprintf("scope contains invalid char '%s', allowed chars are [%s]", invalidChars, r.Charset)
36-
return []string{errMsg}, false
33+
desc := "type can only have these chars [" + r.Charset + "]"
34+
err := "invalid characters [" + invalidChars + "]"
35+
return lint.NewIssue(desc, err), false
3736
}

‎rule/scope_enum.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ func (r *ScopeEnumRule) Apply(setting lint.RuleSetting) error {
4040
}
4141

4242
// Validate validates ScopeEnumRule
43-
func (r *ScopeEnumRule) Validate(msg lint.Commit) ([]string, bool) {
43+
func (r *ScopeEnumRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
4444
if msg.Scope() == "" {
4545
if r.AllowEmpty {
4646
return nil, true
4747
}
4848
errMsg := fmt.Sprintf("empty scope is not allowed, you can use one of %v", r.Scopes)
49-
return []string{errMsg}, false
49+
return lint.NewIssue(errMsg), false
5050
}
5151

5252
isFound := search(r.Scopes, msg.Scope())
53-
if !isFound {
54-
errMsg := fmt.Sprintf("scope '%s' is not allowed, you can use one of %v", msg.Scope(), r.Scopes)
55-
return []string{errMsg}, false
53+
if isFound {
54+
return nil, true
5655
}
57-
return nil, true
56+
57+
errMsg := fmt.Sprintf("scope '%s' is not allowed, you can use one of %v", msg.Scope(), r.Scopes)
58+
return lint.NewIssue(errMsg), false
5859
}

‎rule/scope_max_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *ScopeMaxLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates ScopeMaxLenRule
25-
func (r *ScopeMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLen(r.CheckLen, msg.Scope())
25+
func (r *ScopeMaxLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLen("scope", r.CheckLen, msg.Scope())
2727
}

‎rule/scope_min_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *ScopeMinLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates ScopeMinLenRule
25-
func (r *ScopeMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMinLen(r.CheckLen, msg.Scope())
25+
func (r *ScopeMinLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMinLen("scope", r.CheckLen, msg.Scope())
2727
}

‎rule/type_charset.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package rule
22

33
import (
4-
"fmt"
5-
64
"github.com/conventionalcommit/commitlint/lint"
75
)
86

@@ -26,12 +24,14 @@ func (r *TypeCharsetRule) Apply(setting lint.RuleSetting) error {
2624
}
2725

2826
// Validate validates TypeCharsetRule
29-
func (r *TypeCharsetRule) Validate(msg lint.Commit) ([]string, bool) {
30-
invalidChars, isValid := checkCharset(r.Charset, msg.Type())
27+
func (r *TypeCharsetRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
28+
invalidChars, isValid := validateCharset(r.Charset, msg.Type())
3129
if isValid {
3230
return nil, true
3331
}
3432

35-
errMsg := fmt.Sprintf("type contains invalid char '%s', allowed chars are [%s]", invalidChars, r.Charset)
36-
return []string{errMsg}, false
33+
desc := "type can only have chars [" + r.Charset + "]"
34+
info := "invalid characters [" + invalidChars + "]"
35+
36+
return lint.NewIssue(desc, info), false
3737
}

‎rule/type_enum.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func (r *TypeEnumRule) Apply(setting lint.RuleSetting) error {
2929
}
3030

3131
// Validate validates TypeEnumRule
32-
func (r *TypeEnumRule) Validate(msg lint.Commit) ([]string, bool) {
32+
func (r *TypeEnumRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
3333
isFound := search(r.Types, msg.Type())
34-
if !isFound {
35-
errMsg := fmt.Sprintf("type '%s' is not allowed, you can use one of %v", msg.Type(), r.Types)
36-
return []string{errMsg}, false
34+
if isFound {
35+
return nil, true
3736
}
38-
return nil, true
37+
desc := fmt.Sprintf("type '%s' is not allowed, you can use one of %v", msg.Type(), r.Types)
38+
return lint.NewIssue(desc), false
3939
}

‎rule/type_max_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *TypeMaxLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates TypeMaxLenRule
25-
func (r *TypeMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMaxLen(r.CheckLen, msg.Type())
25+
func (r *TypeMaxLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMaxLen("type", r.CheckLen, msg.Type())
2727
}

‎rule/type_min_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (r *TypeMinLenRule) Apply(setting lint.RuleSetting) error {
2222
}
2323

2424
// Validate validates TypeMinLenRule
25-
func (r *TypeMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26-
return checkMinLen(r.CheckLen, msg.Type())
25+
func (r *TypeMinLenRule) Validate(msg lint.Commit) (*lint.Issue, bool) {
26+
return validateMinLen("type", r.CheckLen, msg.Type())
2727
}

0 commit comments

Comments
 (0)
Please sign in to comment.