Skip to content

Commit 3a8924a

Browse files
build: bump parser to v0.7.1, fix API changes
1 parent 6bd1565 commit 3a8924a

File tree

9 files changed

+30
-32
lines changed

9 files changed

+30
-32
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/conventionalcommit/commitlint
33
go 1.17
44

55
require (
6-
github.com/conventionalcommit/parser v0.5.1
6+
github.com/conventionalcommit/parser v0.7.1
77
github.com/urfave/cli/v2 v2.3.0
88
golang.org/x/mod v0.5.1
99
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2-
github.com/conventionalcommit/parser v0.5.1 h1:IA+fE2bI1R3jUhlO5qesDWQf+e8kXesIQ/w1CD0Pz+I=
3-
github.com/conventionalcommit/parser v0.5.1/go.mod h1:k3teTA7nWpRrk7sjAihpAXm+1QLu1OscGrxclMHgEyc=
2+
github.com/conventionalcommit/parser v0.7.1 h1:oAzcrEqyyGnzCeNOBqGx2qnxISxneUuBiu320chjzMU=
3+
github.com/conventionalcommit/parser v0.7.1/go.mod h1:k3teTA7nWpRrk7sjAihpAXm+1QLu1OscGrxclMHgEyc=
44
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
55
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
66
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=

lint/linter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Package lint provides a simple linter for conventional commits
22
package lint
33

4+
import (
5+
"github.com/conventionalcommit/parser"
6+
)
7+
48
// Linter is linter for commit message
59
type Linter struct {
610
conf *Config
@@ -14,7 +18,7 @@ func New(conf *Config, rules []Rule) (*Linter, error) {
1418
l := &Linter{
1519
conf: conf,
1620
rules: rules,
17-
parser: &defaultParser{},
21+
parser: parser.New(),
1822
}
1923
return l, nil
2024
}
@@ -30,7 +34,7 @@ func (l *Linter) Lint(commitMsg string) (*Failure, error) {
3034

3135
// LintCommit checks the given Commit against rules
3236
func (l *Linter) LintCommit(msg *Commit) (*Failure, error) {
33-
res := newFailure(msg.FullCommit)
37+
res := newFailure(msg.Message())
3438

3539
for _, rule := range l.rules {
3640
currentRule := rule

lint/parser.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ type Commit = parser.Commit
1010
type Parser interface {
1111
Parse(msg string) (*Commit, error)
1212
}
13-
14-
type defaultParser struct{}
15-
16-
func (d *defaultParser) Parse(msg string) (*Commit, error) {
17-
return parser.Parse(msg)
18-
}

rule/charset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *ScopeCharsetRule) Name() string { return "scope-charset" }
1717

1818
// Validate validates ScopeCharsetRule
1919
func (r *ScopeCharsetRule) Validate(msg *lint.Commit) ([]string, bool) {
20-
invalidChar, isValid := checkCharset(r.Charset, msg.Header.Scope)
20+
invalidChar, isValid := checkCharset(r.Charset, msg.Scope())
2121
if !isValid {
2222
errMsg := fmt.Sprintf("scope contains invalid char '%s', allowed chars are [%s]", invalidChar, r.Charset)
2323
return []string{errMsg}, false
@@ -44,7 +44,7 @@ func (r *TypeCharsetRule) Name() string { return "type-charset" }
4444

4545
// Validate validates TypeCharsetRule
4646
func (r *TypeCharsetRule) Validate(msg *lint.Commit) ([]string, bool) {
47-
invalidChar, isValid := checkCharset(r.Charset, msg.Header.Type)
47+
invalidChar, isValid := checkCharset(r.Charset, msg.Type())
4848
if !isValid {
4949
errMsg := fmt.Sprintf("type contains invalid char '%s', allowed chars are [%s]", invalidChar, r.Charset)
5050
return []string{errMsg}, false

rule/enum.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ func (r *ScopeEnumRule) Name() string { return "scope-enum" }
1919

2020
// Validate validates ScopeEnumRule
2121
func (r *ScopeEnumRule) Validate(msg *lint.Commit) ([]string, bool) {
22-
if msg.Header.Scope == "" {
22+
if msg.Scope() == "" {
2323
if r.AllowEmpty {
2424
return nil, true
2525
}
2626
errMsg := fmt.Sprintf("empty scope is not allowed, you can use one of %v", r.Scopes)
2727
return []string{errMsg}, false
2828
}
2929

30-
isFound := search(r.Scopes, msg.Header.Scope)
30+
isFound := search(r.Scopes, msg.Scope())
3131
if !isFound {
32-
errMsg := fmt.Sprintf("scope '%s' is not allowed, you can use one of %v", msg.Header.Scope, r.Scopes)
32+
errMsg := fmt.Sprintf("scope '%s' is not allowed, you can use one of %v", msg.Scope(), r.Scopes)
3333
return []string{errMsg}, false
3434
}
3535
return nil, true
@@ -65,9 +65,9 @@ func (r *TypeEnumRule) Name() string { return "type-enum" }
6565

6666
// Validate validates TypeEnumRule
6767
func (r *TypeEnumRule) Validate(msg *lint.Commit) ([]string, bool) {
68-
isFound := search(r.Types, msg.Header.Type)
68+
isFound := search(r.Types, msg.Type())
6969
if !isFound {
70-
errMsg := fmt.Sprintf("type '%s' is not allowed, you can use one of %v", msg.Header.Type, r.Types)
70+
errMsg := fmt.Sprintf("type '%s' is not allowed, you can use one of %v", msg.Type(), r.Types)
7171
return []string{errMsg}, false
7272
}
7373
return nil, true

rule/max_length.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (r *HeadMaxLenRule) Name() string { return "header-max-length" }
1616

1717
// Validate validates HeadMaxLenRule
1818
func (r *HeadMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
19-
return checkMaxLen(r.CheckLen, msg.Header.FullHeader)
19+
return checkMaxLen(r.CheckLen, msg.Header())
2020
}
2121

2222
// Apply sets the needed argument for the rule
@@ -38,7 +38,7 @@ func (r *BodyMaxLenRule) Name() string { return "body-max-length" }
3838

3939
// Validate validates BodyMaxLenRule
4040
func (r *BodyMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
41-
return checkMaxLen(r.CheckLen, msg.Body)
41+
return checkMaxLen(r.CheckLen, msg.Body())
4242
}
4343

4444
// Apply sets the needed argument for the rule
@@ -60,7 +60,7 @@ func (r *FooterMaxLenRule) Name() string { return "footer-max-length" }
6060

6161
// Validate validates FooterMaxLenRule
6262
func (r *FooterMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
63-
return checkMaxLen(r.CheckLen, msg.Footer.FullFooter)
63+
return checkMaxLen(r.CheckLen, msg.Footer())
6464
}
6565

6666
// Apply sets the needed argument for the rule
@@ -82,7 +82,7 @@ func (r *TypeMaxLenRule) Name() string { return "type-max-length" }
8282

8383
// Validate validates TypeMaxLenRule
8484
func (r *TypeMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
85-
return checkMaxLen(r.CheckLen, msg.Header.Type)
85+
return checkMaxLen(r.CheckLen, msg.Type())
8686
}
8787

8888
// Apply sets the needed argument for the rule
@@ -104,7 +104,7 @@ func (r *ScopeMaxLenRule) Name() string { return "scope-max-length" }
104104

105105
// Validate validates ScopeMaxLenRule
106106
func (r *ScopeMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
107-
return checkMaxLen(r.CheckLen, msg.Header.Scope)
107+
return checkMaxLen(r.CheckLen, msg.Scope())
108108
}
109109

110110
// Apply sets the needed argument for the rule
@@ -126,7 +126,7 @@ func (r *DescriptionMaxLenRule) Name() string { return "description-max-length"
126126

127127
// Validate validates DescriptionMaxLenRule
128128
func (r *DescriptionMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
129-
return checkMaxLen(r.CheckLen, msg.Header.Description)
129+
return checkMaxLen(r.CheckLen, msg.Description())
130130
}
131131

132132
// Apply sets the needed argument for the rule

rule/max_line_length.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *BodyMaxLineLenRule) Name() string { return "body-max-line-length" }
1717

1818
// Validate validates BodyMaxLineLenRule rule
1919
func (r *BodyMaxLineLenRule) Validate(msg *lint.Commit) ([]string, bool) {
20-
return checkMaxLineLength(r.CheckLen, msg.Body)
20+
return checkMaxLineLength(r.CheckLen, msg.Body())
2121
}
2222

2323
// Apply sets the needed argument for the rule
@@ -39,7 +39,7 @@ func (r *FooterMaxLineLenRule) Name() string { return "footer-max-line-length" }
3939

4040
// Validate validates FooterMaxLineLenRule rule
4141
func (r *FooterMaxLineLenRule) Validate(msg *lint.Commit) ([]string, bool) {
42-
return checkMaxLineLength(r.CheckLen, msg.Footer.FullFooter)
42+
return checkMaxLineLength(r.CheckLen, msg.Footer())
4343
}
4444

4545
// Apply sets the needed argument for the rule

rule/min_length.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (r *HeadMinLenRule) Name() string { return "header-min-length" }
1616

1717
// Validate validates HeadMinLenRule
1818
func (r *HeadMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
19-
return checkMinLen(r.CheckLen, msg.Header.FullHeader)
19+
return checkMinLen(r.CheckLen, msg.Header())
2020
}
2121

2222
// Apply sets the needed argument for the rule
@@ -38,7 +38,7 @@ func (r *BodyMinLenRule) Name() string { return "body-min-length" }
3838

3939
// Validate validates BodyMinLenRule
4040
func (r *BodyMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
41-
return checkMinLen(r.CheckLen, msg.Body)
41+
return checkMinLen(r.CheckLen, msg.Body())
4242
}
4343

4444
// Apply sets the needed argument for the rule
@@ -60,7 +60,7 @@ func (r *FooterMinLenRule) Name() string { return "footer-min-length" }
6060

6161
// Validate validates FooterMinLenRule
6262
func (r *FooterMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
63-
return checkMinLen(r.CheckLen, msg.Footer.FullFooter)
63+
return checkMinLen(r.CheckLen, msg.Footer())
6464
}
6565

6666
// Apply sets the needed argument for the rule
@@ -82,7 +82,7 @@ func (r *TypeMinLenRule) Name() string { return "type-min-length" }
8282

8383
// Validate validates TypeMinLenRule
8484
func (r *TypeMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
85-
return checkMinLen(r.CheckLen, msg.Header.Type)
85+
return checkMinLen(r.CheckLen, msg.Type())
8686
}
8787

8888
// Apply sets the needed argument for the rule
@@ -104,7 +104,7 @@ func (r *ScopeMinLenRule) Name() string { return "scope-min-length" }
104104

105105
// Validate validates ScopeMinLenRule
106106
func (r *ScopeMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
107-
return checkMinLen(r.CheckLen, msg.Header.Scope)
107+
return checkMinLen(r.CheckLen, msg.Scope())
108108
}
109109

110110
// Apply sets the needed argument for the rule
@@ -126,7 +126,7 @@ func (r *DescriptionMinLenRule) Name() string { return "description-min-length"
126126

127127
// Validate validates DescriptionMinLenRule
128128
func (r *DescriptionMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
129-
return checkMinLen(r.CheckLen, msg.Header.Description)
129+
return checkMinLen(r.CheckLen, msg.Description())
130130
}
131131

132132
// Apply sets the needed argument for the rule

0 commit comments

Comments
 (0)