Skip to content

Commit ebb158d

Browse files
refactor: merge message pkg with lint
1 parent 2fef570 commit ebb158d

File tree

9 files changed

+38
-39
lines changed

9 files changed

+38
-39
lines changed

lint/linter.go

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

4-
import (
5-
"github.com/conventionalcommit/commitlint/message"
6-
)
7-
84
// Linter is linter for commit message
95
type Linter struct {
106
conf *Config
@@ -18,7 +14,7 @@ func NewLinter(conf *Config, rules []Rule) (*Linter, error) {
1814

1915
// Lint checks the given commitMsg string against rules
2016
func (l *Linter) Lint(commitMsg string) (*Result, error) {
21-
msg, isHeaderErr, err := message.Parse(commitMsg)
17+
msg, isHeaderErr, err := Parse(commitMsg)
2218
if err != nil {
2319
if isHeaderErr {
2420
return l.headerErrorRule(commitMsg), nil
@@ -28,8 +24,8 @@ func (l *Linter) Lint(commitMsg string) (*Result, error) {
2824
return l.LintCommit(msg)
2925
}
3026

31-
// LintCommit checks the given message.Commit against rules
32-
func (l *Linter) LintCommit(msg *message.Commit) (*Result, error) {
27+
// LintCommit checks the given Commit against rules
28+
func (l *Linter) LintCommit(msg *Commit) (*Result, error) {
3329
res := newResult(msg.FullCommit)
3430

3531
for _, rule := range l.rules {

lint/message.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package lint
2+
3+
import "github.com/conventionalcommit/parser"
4+
5+
// Commit represent a commit message
6+
// for now it is an alias of parser.Commit
7+
type Commit = parser.Commit

message/commit.go renamed to lint/parse.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// Package message contains commit message
2-
package message
1+
package lint
32

4-
import "github.com/conventionalcommit/parser"
5-
6-
// Commit is alias for parser.Commit
7-
type Commit = parser.Commit
3+
import (
4+
"github.com/conventionalcommit/parser"
5+
)
86

97
// Parse parses given msg and checks for header error
108
func Parse(msg string) (*Commit, bool, error) {

lint/rule.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package lint
22

3-
import "github.com/conventionalcommit/commitlint/message"
4-
53
// Rule represent a linter rule
64
type Rule interface {
75
// Name returns name of the rule, it should be a unique identifier
@@ -15,5 +13,5 @@ type Rule interface {
1513
// Validate validates the rule for given message
1614
// if given message is valid, return true and result string is ignored
1715
// if invalid, return a error result with false
18-
Validate(msg *message.Commit) (result string, isValid bool)
16+
Validate(msg *Commit) (result string, isValid bool)
1917
}

rule/charset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/conventionalcommit/commitlint/message"
7+
"github.com/conventionalcommit/commitlint/lint"
88
)
99

1010
// ScopeCharsetRule to validate max length of header
@@ -16,7 +16,7 @@ type ScopeCharsetRule struct {
1616
func (r *ScopeCharsetRule) Name() string { return "scope-charset" }
1717

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

4141
// Validate validates TypeCharsetRule
42-
func (r *TypeCharsetRule) Validate(msg *message.Commit) (string, bool) {
42+
func (r *TypeCharsetRule) Validate(msg *lint.Commit) (string, bool) {
4343
invalidChar, isValid := checkCharset(r.Charset, msg.Header.Type)
4444
if !isValid {
4545
errMsg := fmt.Sprintf("type contains invalid char '%s', allowed chars are [%s]", invalidChar, r.Charset)

rule/enum.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"sort"
66

7-
"github.com/conventionalcommit/commitlint/message"
7+
"github.com/conventionalcommit/commitlint/lint"
88
)
99

1010
// ScopeEnumRule to validate max length of header
@@ -18,7 +18,7 @@ type ScopeEnumRule struct {
1818
func (r *ScopeEnumRule) Name() string { return "scope-enum" }
1919

2020
// Validate validates ScopeEnumRule
21-
func (r *ScopeEnumRule) Validate(msg *message.Commit) (string, bool) {
21+
func (r *ScopeEnumRule) Validate(msg *lint.Commit) (string, bool) {
2222
if msg.Header.Scope == "" {
2323
if r.AllowEmpty {
2424
return "", true
@@ -64,7 +64,7 @@ type TypeEnumRule struct {
6464
func (r *TypeEnumRule) Name() string { return "type-enum" }
6565

6666
// Validate validates TypeEnumRule
67-
func (r *TypeEnumRule) Validate(msg *message.Commit) (string, bool) {
67+
func (r *TypeEnumRule) Validate(msg *lint.Commit) (string, bool) {
6868
isFound := search(r.Types, msg.Header.Type)
6969
if !isFound {
7070
errMsg := fmt.Sprintf("type '%s' is not allowed, you can use one of %v", msg.Header.Type, r.Types)

rule/max_length.go

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

6-
"github.com/conventionalcommit/commitlint/message"
6+
"github.com/conventionalcommit/commitlint/lint"
77
)
88

99
// HeadMaxLenRule to validate max length of header
@@ -15,7 +15,7 @@ type HeadMaxLenRule struct {
1515
func (r *HeadMaxLenRule) Name() string { return "header-max-length" }
1616

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

@@ -33,7 +33,7 @@ type BodyMaxLenRule struct {
3333
func (r *BodyMaxLenRule) Name() string { return "body-max-length" }
3434

3535
// Validate validates BodyMaxLenRule
36-
func (r *BodyMaxLenRule) Validate(msg *message.Commit) (string, bool) {
36+
func (r *BodyMaxLenRule) Validate(msg *lint.Commit) (string, bool) {
3737
return checkMaxLen(r.CheckLen, msg.Body)
3838
}
3939

@@ -51,7 +51,7 @@ type FooterMaxLenRule struct {
5151
func (r *FooterMaxLenRule) Name() string { return "footer-max-length" }
5252

5353
// Validate validates FooterMaxLenRule
54-
func (r *FooterMaxLenRule) Validate(msg *message.Commit) (string, bool) {
54+
func (r *FooterMaxLenRule) Validate(msg *lint.Commit) (string, bool) {
5555
return checkMaxLen(r.CheckLen, msg.Footer.FullFooter)
5656
}
5757

@@ -69,7 +69,7 @@ type TypeMaxLenRule struct {
6969
func (r *TypeMaxLenRule) Name() string { return "type-max-length" }
7070

7171
// Validate validates TypeMaxLenRule
72-
func (r *TypeMaxLenRule) Validate(msg *message.Commit) (string, bool) {
72+
func (r *TypeMaxLenRule) Validate(msg *lint.Commit) (string, bool) {
7373
return checkMaxLen(r.CheckLen, msg.Header.Type)
7474
}
7575

@@ -87,7 +87,7 @@ type ScopeMaxLenRule struct {
8787
func (r *ScopeMaxLenRule) Name() string { return "scope-max-length" }
8888

8989
// Validate validates ScopeMaxLenRule
90-
func (r *ScopeMaxLenRule) Validate(msg *message.Commit) (string, bool) {
90+
func (r *ScopeMaxLenRule) Validate(msg *lint.Commit) (string, bool) {
9191
return checkMaxLen(r.CheckLen, msg.Header.Scope)
9292
}
9393

@@ -105,7 +105,7 @@ type DescriptionMaxLenRule struct {
105105
func (r *DescriptionMaxLenRule) Name() string { return "description-max-length" }
106106

107107
// Validate validates DescriptionMaxLenRule
108-
func (r *DescriptionMaxLenRule) Validate(msg *message.Commit) (string, bool) {
108+
func (r *DescriptionMaxLenRule) Validate(msg *lint.Commit) (string, bool) {
109109
return checkMaxLen(r.CheckLen, msg.Header.Description)
110110
}
111111

rule/max_line_length.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/conventionalcommit/commitlint/message"
7+
"github.com/conventionalcommit/commitlint/lint"
88
)
99

1010
// BodyMaxLineLenRule to validate max line length of body
@@ -16,7 +16,7 @@ type BodyMaxLineLenRule struct {
1616
func (r *BodyMaxLineLenRule) Name() string { return "body-max-line-length" }
1717

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

@@ -34,7 +34,7 @@ type FooterMaxLineLenRule struct {
3434
func (r *FooterMaxLineLenRule) Name() string { return "footer-max-line-length" }
3535

3636
// Validate validates FooterMaxLineLenRule rule
37-
func (r *FooterMaxLineLenRule) Validate(msg *message.Commit) (string, bool) {
37+
func (r *FooterMaxLineLenRule) Validate(msg *lint.Commit) (string, bool) {
3838
return checkMaxLineLength(r.CheckLen, msg.Footer.FullFooter)
3939
}
4040

rule/min_length.go

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

6-
"github.com/conventionalcommit/commitlint/message"
6+
"github.com/conventionalcommit/commitlint/lint"
77
)
88

99
// HeadMinLenRule to validate min length of header
@@ -15,7 +15,7 @@ type HeadMinLenRule struct {
1515
func (r *HeadMinLenRule) Name() string { return "header-min-length" }
1616

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

@@ -33,7 +33,7 @@ type BodyMinLenRule struct {
3333
func (r *BodyMinLenRule) Name() string { return "body-min-length" }
3434

3535
// Validate validates BodyMinLenRule
36-
func (r *BodyMinLenRule) Validate(msg *message.Commit) (string, bool) {
36+
func (r *BodyMinLenRule) Validate(msg *lint.Commit) (string, bool) {
3737
return checkMinLen(r.CheckLen, msg.Body)
3838
}
3939

@@ -51,7 +51,7 @@ type FooterMinLenRule struct {
5151
func (r *FooterMinLenRule) Name() string { return "footer-min-length" }
5252

5353
// Validate validates FooterMinLenRule
54-
func (r *FooterMinLenRule) Validate(msg *message.Commit) (string, bool) {
54+
func (r *FooterMinLenRule) Validate(msg *lint.Commit) (string, bool) {
5555
return checkMinLen(r.CheckLen, msg.Footer.FullFooter)
5656
}
5757

@@ -69,7 +69,7 @@ type TypeMinLenRule struct {
6969
func (r *TypeMinLenRule) Name() string { return "type-min-length" }
7070

7171
// Validate validates TypeMinLenRule
72-
func (r *TypeMinLenRule) Validate(msg *message.Commit) (string, bool) {
72+
func (r *TypeMinLenRule) Validate(msg *lint.Commit) (string, bool) {
7373
return checkMinLen(r.CheckLen, msg.Header.Type)
7474
}
7575

@@ -87,7 +87,7 @@ type ScopeMinLenRule struct {
8787
func (r *ScopeMinLenRule) Name() string { return "scope-min-length" }
8888

8989
// Validate validates ScopeMinLenRule
90-
func (r *ScopeMinLenRule) Validate(msg *message.Commit) (string, bool) {
90+
func (r *ScopeMinLenRule) Validate(msg *lint.Commit) (string, bool) {
9191
return checkMinLen(r.CheckLen, msg.Header.Scope)
9292
}
9393

@@ -105,7 +105,7 @@ type DescriptionMinLenRule struct {
105105
func (r *DescriptionMinLenRule) Name() string { return "description-min-length" }
106106

107107
// Validate validates DescriptionMinLenRule
108-
func (r *DescriptionMinLenRule) Validate(msg *message.Commit) (string, bool) {
108+
func (r *DescriptionMinLenRule) Validate(msg *lint.Commit) (string, bool) {
109109
return checkMinLen(r.CheckLen, msg.Header.Description)
110110
}
111111

0 commit comments

Comments
 (0)