Skip to content

Commit 2faff74

Browse files
refactor(rule): move rule into their own file
1 parent d7c2fb1 commit 2faff74

28 files changed

+757
-665
lines changed

rule/body_max_length.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package rule
2+
3+
import "github.com/conventionalcommit/commitlint/lint"
4+
5+
var _ lint.Rule = (*BodyMaxLenRule)(nil)
6+
7+
// BodyMaxLenRule to validate max length of body
8+
type BodyMaxLenRule struct {
9+
CheckLen int
10+
}
11+
12+
// Name return name of the rule
13+
func (r *BodyMaxLenRule) Name() string { return "body-max-length" }
14+
15+
// Apply sets the needed argument for the rule
16+
func (r *BodyMaxLenRule) Apply(setting lint.RuleSetting) error {
17+
err := setIntArg(&r.CheckLen, setting.Argument)
18+
if err != nil {
19+
return errInvalidArg(r.Name(), err)
20+
}
21+
return nil
22+
}
23+
24+
// Validate validates BodyMaxLenRule
25+
func (r *BodyMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26+
return checkMaxLen(r.CheckLen, msg.Body())
27+
}

rule/body_max_line_length.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package rule
2+
3+
import (
4+
"github.com/conventionalcommit/commitlint/lint"
5+
)
6+
7+
var _ lint.Rule = (*BodyMaxLineLenRule)(nil)
8+
9+
// BodyMaxLineLenRule to validate max line length of body
10+
type BodyMaxLineLenRule struct {
11+
CheckLen int
12+
}
13+
14+
// Name return name of the rule
15+
func (r *BodyMaxLineLenRule) Name() string { return "body-max-line-length" }
16+
17+
// Apply sets the needed argument for the rule
18+
func (r *BodyMaxLineLenRule) Apply(setting lint.RuleSetting) error {
19+
err := setIntArg(&r.CheckLen, setting.Argument)
20+
if err != nil {
21+
return errInvalidArg(r.Name(), err)
22+
}
23+
return nil
24+
}
25+
26+
// Validate validates BodyMaxLineLenRule rule
27+
func (r *BodyMaxLineLenRule) Validate(msg lint.Commit) ([]string, bool) {
28+
return checkMaxLineLength(r.CheckLen, msg.Body())
29+
}

rule/body_min_length.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package rule
2+
3+
import "github.com/conventionalcommit/commitlint/lint"
4+
5+
var _ lint.Rule = (*BodyMinLenRule)(nil)
6+
7+
// BodyMinLenRule to validate min length of body
8+
type BodyMinLenRule struct {
9+
CheckLen int
10+
}
11+
12+
// Name return name of the rule
13+
func (r *BodyMinLenRule) Name() string { return "body-min-length" }
14+
15+
// Apply sets the needed argument for the rule
16+
func (r *BodyMinLenRule) Apply(setting lint.RuleSetting) error {
17+
err := setIntArg(&r.CheckLen, setting.Argument)
18+
if err != nil {
19+
return errInvalidArg(r.Name(), err)
20+
}
21+
return nil
22+
}
23+
24+
// Validate validates BodyMinLenRule
25+
func (r *BodyMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26+
return checkMinLen(r.CheckLen, msg.Body())
27+
}

rule/charset.go

Lines changed: 0 additions & 71 deletions
This file was deleted.

rule/desc_max_length.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package rule
2+
3+
import "github.com/conventionalcommit/commitlint/lint"
4+
5+
var _ lint.Rule = (*DescriptionMaxLenRule)(nil)
6+
7+
// DescriptionMaxLenRule to validate max length of type
8+
type DescriptionMaxLenRule struct {
9+
CheckLen int
10+
}
11+
12+
// Name return name of the rule
13+
func (r *DescriptionMaxLenRule) Name() string { return "description-max-length" }
14+
15+
// Apply sets the needed argument for the rule
16+
func (r *DescriptionMaxLenRule) Apply(setting lint.RuleSetting) error {
17+
err := setIntArg(&r.CheckLen, setting.Argument)
18+
if err != nil {
19+
return errInvalidArg(r.Name(), err)
20+
}
21+
return nil
22+
}
23+
24+
// Validate validates DescriptionMaxLenRule
25+
func (r *DescriptionMaxLenRule) Validate(msg lint.Commit) ([]string, bool) {
26+
return checkMaxLen(r.CheckLen, msg.Description())
27+
}

rule/desc_min_length.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package rule
2+
3+
import "github.com/conventionalcommit/commitlint/lint"
4+
5+
var _ lint.Rule = (*DescriptionMinLenRule)(nil)
6+
7+
// DescriptionMinLenRule to validate min length of description
8+
type DescriptionMinLenRule struct {
9+
CheckLen int
10+
}
11+
12+
// Name return name of the rule
13+
func (r *DescriptionMinLenRule) Name() string { return "description-min-length" }
14+
15+
// Apply sets the needed argument for the rule
16+
func (r *DescriptionMinLenRule) Apply(setting lint.RuleSetting) error {
17+
err := setIntArg(&r.CheckLen, setting.Argument)
18+
if err != nil {
19+
return errInvalidArg(r.Name(), err)
20+
}
21+
return nil
22+
}
23+
24+
// Validate validates DescriptionMinLenRule
25+
func (r *DescriptionMinLenRule) Validate(msg lint.Commit) ([]string, bool) {
26+
return checkMinLen(r.CheckLen, msg.Description())
27+
}

rule/doc.go

Lines changed: 0 additions & 2 deletions
This file was deleted.

rule/enum.go

Lines changed: 0 additions & 129 deletions
This file was deleted.

rule/errors.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)