Skip to content

Commit 03ff16b

Browse files
refactor(lint)!: rule.Apply accept RuleSetting
1 parent 8b8ccfc commit 03ff16b

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ func Validate(conf *lint.Config) []error {
8383
}
8484
}
8585

86-
for ruleName, r := range conf.Settings {
86+
for ruleName, ruleSetting := range conf.Settings {
8787
// Check if rule is registered
8888
ruleData, ok := registry.GetRule(ruleName)
8989
if !ok {
9090
errs = append(errs, fmt.Errorf("unknown rule '%s'", ruleName))
9191
continue
9292
}
9393

94-
err := ruleData.Apply(r.Argument, r.Flags)
94+
err := ruleData.Apply(ruleSetting)
9595
if err != nil {
9696
errs = append(errs, err)
9797
}

config/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func GetEnabledRules(conf *lint.Config) ([]lint.Rule, error) {
5353
return nil, fmt.Errorf("config error: '%s' rule settings not found", ruleName)
5454
}
5555

56-
err := r.Apply(rConf.Argument, rConf.Flags)
56+
err := r.Apply(rConf)
5757
if err != nil {
5858
return nil, fmt.Errorf("config error: %v", err)
5959
}

lint/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Rule interface {
5050
// Apply calls with arguments and flags for the rule from config file
5151
// if flags or arguments are invalid or not expected return an error
5252
// Apply is called before Validate
53-
Apply(arg interface{}, flags map[string]interface{}) error
53+
Apply(setting RuleSetting) error
5454

5555
// Validate validates the rule for given commit message
5656
// if given commit is valid, return true and messages slice are ignored

rule/charset.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func (r *ScopeCharsetRule) Validate(msg *lint.Commit) ([]string, bool) {
2626
}
2727

2828
// Apply sets the needed argument for the rule
29-
func (r *ScopeCharsetRule) Apply(arg interface{}, flags map[string]interface{}) error {
30-
err := setStringArg(&r.Charset, arg)
29+
func (r *ScopeCharsetRule) Apply(setting lint.RuleSetting) error {
30+
err := setStringArg(&r.Charset, setting.Argument)
3131
if err != nil {
3232
return errInvalidArg(r.Name(), err)
3333
}
@@ -53,8 +53,8 @@ func (r *TypeCharsetRule) Validate(msg *lint.Commit) ([]string, bool) {
5353
}
5454

5555
// Apply sets the needed argument for the rule
56-
func (r *TypeCharsetRule) Apply(arg interface{}, flags map[string]interface{}) error {
57-
err := setStringArg(&r.Charset, arg)
56+
func (r *TypeCharsetRule) Apply(setting lint.RuleSetting) error {
57+
err := setStringArg(&r.Charset, setting.Argument)
5858
if err != nil {
5959
return errInvalidArg(r.Name(), err)
6060
}

rule/enum.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func (r *ScopeEnumRule) Validate(msg *lint.Commit) ([]string, bool) {
3636
}
3737

3838
// Apply sets the needed argument for the rule
39-
func (r *ScopeEnumRule) Apply(arg interface{}, flags map[string]interface{}) error {
40-
err := setStringArrArg(&r.Scopes, arg)
39+
func (r *ScopeEnumRule) Apply(setting lint.RuleSetting) error {
40+
err := setStringArrArg(&r.Scopes, setting.Argument)
4141
if err != nil {
4242
return errInvalidArg(r.Name(), err)
4343
}
4444

45-
allowEmpty, ok := flags["allow-empty"]
45+
allowEmpty, ok := setting.Flags["allow-empty"]
4646
if ok {
4747
err := setBoolArg(&r.AllowEmpty, allowEmpty)
4848
if err != nil {
@@ -74,8 +74,8 @@ func (r *TypeEnumRule) Validate(msg *lint.Commit) ([]string, bool) {
7474
}
7575

7676
// Apply sets the needed argument for the rule
77-
func (r *TypeEnumRule) Apply(arg interface{}, flags map[string]interface{}) error {
78-
err := setStringArrArg(&r.Types, arg)
77+
func (r *TypeEnumRule) Apply(setting lint.RuleSetting) error {
78+
err := setStringArrArg(&r.Types, setting.Argument)
7979
if err != nil {
8080
return errInvalidArg(r.Name(), err)
8181
}
@@ -111,8 +111,8 @@ func (r *FooterEnumRule) Validate(msg *lint.Commit) ([]string, bool) {
111111
}
112112

113113
// Apply sets the needed argument for the rule
114-
func (r *FooterEnumRule) Apply(arg interface{}, flags map[string]interface{}) error {
115-
err := setStringArrArg(&r.Tokens, arg)
114+
func (r *FooterEnumRule) Apply(setting lint.RuleSetting) error {
115+
err := setStringArrArg(&r.Tokens, setting.Argument)
116116
if err != nil {
117117
return errInvalidArg(r.Name(), err)
118118
}

rule/max_length.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func (r *HeadMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
2020
}
2121

2222
// Apply sets the needed argument for the rule
23-
func (r *HeadMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
24-
err := setIntArg(&r.CheckLen, arg)
23+
func (r *HeadMaxLenRule) Apply(setting lint.RuleSetting) error {
24+
err := setIntArg(&r.CheckLen, setting.Argument)
2525
if err != nil {
2626
return errInvalidArg(r.Name(), err)
2727
}
@@ -42,8 +42,8 @@ func (r *BodyMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
4242
}
4343

4444
// Apply sets the needed argument for the rule
45-
func (r *BodyMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
46-
err := setIntArg(&r.CheckLen, arg)
45+
func (r *BodyMaxLenRule) Apply(setting lint.RuleSetting) error {
46+
err := setIntArg(&r.CheckLen, setting.Argument)
4747
if err != nil {
4848
return errInvalidArg(r.Name(), err)
4949
}
@@ -64,8 +64,8 @@ func (r *FooterMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
6464
}
6565

6666
// Apply sets the needed argument for the rule
67-
func (r *FooterMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
68-
err := setIntArg(&r.CheckLen, arg)
67+
func (r *FooterMaxLenRule) Apply(setting lint.RuleSetting) error {
68+
err := setIntArg(&r.CheckLen, setting.Argument)
6969
if err != nil {
7070
return errInvalidArg(r.Name(), err)
7171
}
@@ -86,8 +86,8 @@ func (r *TypeMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
8686
}
8787

8888
// Apply sets the needed argument for the rule
89-
func (r *TypeMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
90-
err := setIntArg(&r.CheckLen, arg)
89+
func (r *TypeMaxLenRule) Apply(setting lint.RuleSetting) error {
90+
err := setIntArg(&r.CheckLen, setting.Argument)
9191
if err != nil {
9292
return errInvalidArg(r.Name(), err)
9393
}
@@ -108,8 +108,8 @@ func (r *ScopeMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
108108
}
109109

110110
// Apply sets the needed argument for the rule
111-
func (r *ScopeMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
112-
err := setIntArg(&r.CheckLen, arg)
111+
func (r *ScopeMaxLenRule) Apply(setting lint.RuleSetting) error {
112+
err := setIntArg(&r.CheckLen, setting.Argument)
113113
if err != nil {
114114
return errInvalidArg(r.Name(), err)
115115
}
@@ -130,8 +130,8 @@ func (r *DescriptionMaxLenRule) Validate(msg *lint.Commit) ([]string, bool) {
130130
}
131131

132132
// Apply sets the needed argument for the rule
133-
func (r *DescriptionMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
134-
err := setIntArg(&r.CheckLen, arg)
133+
func (r *DescriptionMaxLenRule) Apply(setting lint.RuleSetting) error {
134+
err := setIntArg(&r.CheckLen, setting.Argument)
135135
if err != nil {
136136
return errInvalidArg(r.Name(), err)
137137
}

rule/max_line_length.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func (r *BodyMaxLineLenRule) Validate(msg *lint.Commit) ([]string, bool) {
2121
}
2222

2323
// Apply sets the needed argument for the rule
24-
func (r *BodyMaxLineLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
25-
err := setIntArg(&r.CheckLen, arg)
24+
func (r *BodyMaxLineLenRule) Apply(setting lint.RuleSetting) error {
25+
err := setIntArg(&r.CheckLen, setting.Argument)
2626
if err != nil {
2727
return errInvalidArg(r.Name(), err)
2828
}
@@ -43,8 +43,8 @@ func (r *FooterMaxLineLenRule) Validate(msg *lint.Commit) ([]string, bool) {
4343
}
4444

4545
// Apply sets the needed argument for the rule
46-
func (r *FooterMaxLineLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
47-
err := setIntArg(&r.CheckLen, arg)
46+
func (r *FooterMaxLineLenRule) Apply(setting lint.RuleSetting) error {
47+
err := setIntArg(&r.CheckLen, setting.Argument)
4848
if err != nil {
4949
return errInvalidArg(r.Name(), err)
5050
}

rule/min_length.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func (r *HeadMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
2020
}
2121

2222
// Apply sets the needed argument for the rule
23-
func (r *HeadMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
24-
err := setIntArg(&r.CheckLen, arg)
23+
func (r *HeadMinLenRule) Apply(setting lint.RuleSetting) error {
24+
err := setIntArg(&r.CheckLen, setting.Argument)
2525
if err != nil {
2626
return errInvalidArg(r.Name(), err)
2727
}
@@ -42,8 +42,8 @@ func (r *BodyMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
4242
}
4343

4444
// Apply sets the needed argument for the rule
45-
func (r *BodyMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
46-
err := setIntArg(&r.CheckLen, arg)
45+
func (r *BodyMinLenRule) Apply(setting lint.RuleSetting) error {
46+
err := setIntArg(&r.CheckLen, setting.Argument)
4747
if err != nil {
4848
return errInvalidArg(r.Name(), err)
4949
}
@@ -64,8 +64,8 @@ func (r *FooterMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
6464
}
6565

6666
// Apply sets the needed argument for the rule
67-
func (r *FooterMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
68-
err := setIntArg(&r.CheckLen, arg)
67+
func (r *FooterMinLenRule) Apply(setting lint.RuleSetting) error {
68+
err := setIntArg(&r.CheckLen, setting.Argument)
6969
if err != nil {
7070
return errInvalidArg(r.Name(), err)
7171
}
@@ -86,8 +86,8 @@ func (r *TypeMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
8686
}
8787

8888
// Apply sets the needed argument for the rule
89-
func (r *TypeMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
90-
err := setIntArg(&r.CheckLen, arg)
89+
func (r *TypeMinLenRule) Apply(setting lint.RuleSetting) error {
90+
err := setIntArg(&r.CheckLen, setting.Argument)
9191
if err != nil {
9292
return errInvalidArg(r.Name(), err)
9393
}
@@ -108,8 +108,8 @@ func (r *ScopeMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
108108
}
109109

110110
// Apply sets the needed argument for the rule
111-
func (r *ScopeMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
112-
err := setIntArg(&r.CheckLen, arg)
111+
func (r *ScopeMinLenRule) Apply(setting lint.RuleSetting) error {
112+
err := setIntArg(&r.CheckLen, setting.Argument)
113113
if err != nil {
114114
return errInvalidArg(r.Name(), err)
115115
}
@@ -130,8 +130,8 @@ func (r *DescriptionMinLenRule) Validate(msg *lint.Commit) ([]string, bool) {
130130
}
131131

132132
// Apply sets the needed argument for the rule
133-
func (r *DescriptionMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
134-
err := setIntArg(&r.CheckLen, arg)
133+
func (r *DescriptionMinLenRule) Apply(setting lint.RuleSetting) error {
134+
err := setIntArg(&r.CheckLen, setting.Argument)
135135
if err != nil {
136136
return errInvalidArg(r.Name(), err)
137137
}

0 commit comments

Comments
 (0)