Skip to content

Commit ed9f3fa

Browse files
feat!: add Flags in rule
1 parent f46b51c commit ed9f3fa

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func GetRules(conf *lint.Config) ([]lint.Rule, error) {
119119
return nil, fmt.Errorf("unknown rule: %s", ruleName)
120120
}
121121
if ruleConfig.Enabled {
122-
err := r.Apply(ruleConfig.Argument)
122+
err := r.Apply(ruleConfig.Argument, ruleConfig.Flags)
123123
if err != nil {
124124
return nil, err
125125
}

lint/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type RuleConfig struct {
1717
Enabled bool `yaml:"enabled"`
1818
Severity string `yaml:"severity"`
1919
Argument interface{} `yaml:"argument"`
20+
21+
// Optional flags
22+
Flags map[string]interface{} `yaml:"flags"`
2023
}
2124

2225
// GetRule returns RuleConfig for given ruleName

lint/rule.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ type Rule interface {
77
// Name returns name of the rule, it should be a unique identifier
88
Name() string
99

10-
// Apply sets the argument to the rule from config file
11-
// if args are invalid or not expected return an error
10+
// Apply calls with arguments and flags for the rule from config file
11+
// if flags or arguments are invalid or not expected return an error
1212
// Apply is called before Validate
13-
Apply(arg interface{}) error
13+
Apply(arg interface{}, flags map[string]interface{}) error
1414

1515
// Validate validates the rule for given message
1616
Validate(msg *message.Commit) (result string, isValid bool)

rule/charset.go

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

2828
// Apply sets the needed argument for the rule
29-
func (r *ScopeCharsetRule) Apply(arg interface{}) error {
29+
func (r *ScopeCharsetRule) Apply(arg interface{}, flags map[string]interface{}) error {
3030
return setStringArg(&r.Charset, arg, r.Name())
3131
}
3232

@@ -49,7 +49,7 @@ func (r *TypeCharsetRule) Validate(msg *message.Commit) (string, bool) {
4949
}
5050

5151
// Apply sets the needed argument for the rule
52-
func (r *TypeCharsetRule) Apply(arg interface{}) error {
52+
func (r *TypeCharsetRule) Apply(arg interface{}, flags map[string]interface{}) error {
5353
return setStringArg(&r.Charset, arg, r.Name())
5454
}
5555

rule/enum.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (r *ScopeEnumRule) Validate(msg *message.Commit) (string, bool) {
2626
}
2727

2828
// Apply sets the needed argument for the rule
29-
func (r *ScopeEnumRule) Apply(arg interface{}) error {
29+
func (r *ScopeEnumRule) Apply(arg interface{}, flags map[string]interface{}) error {
3030
err := setStringArrArg(&r.Scopes, arg, r.Name())
3131
if err != nil {
3232
return err
@@ -55,7 +55,7 @@ func (r *TypeEnumRule) Validate(msg *message.Commit) (string, bool) {
5555
}
5656

5757
// Apply sets the needed argument for the rule
58-
func (r *TypeEnumRule) Apply(arg interface{}) error {
58+
func (r *TypeEnumRule) Apply(arg interface{}, flags map[string]interface{}) error {
5959
err := setStringArrArg(&r.Types, arg, r.Name())
6060
if err != nil {
6161
return err

rule/max_length.go

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

2222
// Apply sets the needed argument for the rule
23-
func (r *HeadMaxLenRule) Apply(arg interface{}) error {
23+
func (r *HeadMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
2424
return setIntArg(&r.CheckLen, arg, r.Name())
2525
}
2626

@@ -38,7 +38,7 @@ func (r *BodyMaxLenRule) Validate(msg *message.Commit) (string, bool) {
3838
}
3939

4040
// Apply sets the needed argument for the rule
41-
func (r *BodyMaxLenRule) Apply(arg interface{}) error {
41+
func (r *BodyMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
4242
return setIntArg(&r.CheckLen, arg, r.Name())
4343
}
4444

@@ -56,7 +56,7 @@ func (r *FooterMaxLenRule) Validate(msg *message.Commit) (string, bool) {
5656
}
5757

5858
// Apply sets the needed argument for the rule
59-
func (r *FooterMaxLenRule) Apply(arg interface{}) error {
59+
func (r *FooterMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
6060
return setIntArg(&r.CheckLen, arg, r.Name())
6161
}
6262

@@ -74,7 +74,7 @@ func (r *TypeMaxLenRule) Validate(msg *message.Commit) (string, bool) {
7474
}
7575

7676
// Apply sets the needed argument for the rule
77-
func (r *TypeMaxLenRule) Apply(arg interface{}) error {
77+
func (r *TypeMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
7878
return setIntArg(&r.CheckLen, arg, r.Name())
7979
}
8080

@@ -92,7 +92,7 @@ func (r *ScopeMaxLenRule) Validate(msg *message.Commit) (string, bool) {
9292
}
9393

9494
// Apply sets the needed argument for the rule
95-
func (r *ScopeMaxLenRule) Apply(arg interface{}) error {
95+
func (r *ScopeMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
9696
return setIntArg(&r.CheckLen, arg, r.Name())
9797
}
9898

@@ -110,7 +110,7 @@ func (r *DescriptionMaxLenRule) Validate(msg *message.Commit) (string, bool) {
110110
}
111111

112112
// Apply sets the needed argument for the rule
113-
func (r *DescriptionMaxLenRule) Apply(arg interface{}) error {
113+
func (r *DescriptionMaxLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
114114
return setIntArg(&r.CheckLen, arg, r.Name())
115115
}
116116

rule/max_line_length.go

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

2323
// Apply sets the needed argument for the rule
24-
func (r *BodyMaxLineLenRule) Apply(arg interface{}) error {
24+
func (r *BodyMaxLineLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
2525
return setIntArg(&r.CheckLen, arg, r.Name())
2626
}
2727

@@ -39,7 +39,7 @@ func (r *FooterMaxLineLenRule) Validate(msg *message.Commit) (string, bool) {
3939
}
4040

4141
// Apply sets the needed argument for the rule
42-
func (r *FooterMaxLineLenRule) Apply(arg interface{}) error {
42+
func (r *FooterMaxLineLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
4343
return setIntArg(&r.CheckLen, arg, r.Name())
4444
}
4545

rule/min_length.go

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

2222
// Apply sets the needed argument for the rule
23-
func (r *HeadMinLenRule) Apply(arg interface{}) error {
23+
func (r *HeadMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
2424
return setIntArg(&r.CheckLen, arg, r.Name())
2525
}
2626

@@ -38,7 +38,7 @@ func (r *BodyMinLenRule) Validate(msg *message.Commit) (string, bool) {
3838
}
3939

4040
// Apply sets the needed argument for the rule
41-
func (r *BodyMinLenRule) Apply(arg interface{}) error {
41+
func (r *BodyMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
4242
return setIntArg(&r.CheckLen, arg, r.Name())
4343
}
4444

@@ -56,7 +56,7 @@ func (r *FooterMinLenRule) Validate(msg *message.Commit) (string, bool) {
5656
}
5757

5858
// Apply sets the needed argument for the rule
59-
func (r *FooterMinLenRule) Apply(arg interface{}) error {
59+
func (r *FooterMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
6060
return setIntArg(&r.CheckLen, arg, r.Name())
6161
}
6262

@@ -74,7 +74,7 @@ func (r *TypeMinLenRule) Validate(msg *message.Commit) (string, bool) {
7474
}
7575

7676
// Apply sets the needed argument for the rule
77-
func (r *TypeMinLenRule) Apply(arg interface{}) error {
77+
func (r *TypeMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
7878
return setIntArg(&r.CheckLen, arg, r.Name())
7979
}
8080

@@ -92,7 +92,7 @@ func (r *ScopeMinLenRule) Validate(msg *message.Commit) (string, bool) {
9292
}
9393

9494
// Apply sets the needed argument for the rule
95-
func (r *ScopeMinLenRule) Apply(arg interface{}) error {
95+
func (r *ScopeMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
9696
return setIntArg(&r.CheckLen, arg, r.Name())
9797
}
9898

@@ -110,7 +110,7 @@ func (r *DescriptionMinLenRule) Validate(msg *message.Commit) (string, bool) {
110110
}
111111

112112
// Apply sets the needed argument for the rule
113-
func (r *DescriptionMinLenRule) Apply(arg interface{}) error {
113+
func (r *DescriptionMinLenRule) Apply(arg interface{}, flags map[string]interface{}) error {
114114
return setIntArg(&r.CheckLen, arg, r.Name())
115115
}
116116

0 commit comments

Comments
 (0)