Skip to content

Commit 8aac3d1

Browse files
committed
fix: rule severity should be different than the default one
1 parent a23a896 commit 8aac3d1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/config/severity.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ func (s *Severity) Validate() error {
2020
}
2121

2222
for i, rule := range s.Rules {
23+
if s.Default == rule.Severity {
24+
return fmt.Errorf("error in severity rule #%d: the default severity (%q) is the same as the rule severity, this rule can be removed",
25+
i, s.Default)
26+
}
27+
2328
if err := rule.Validate(); err != nil {
2429
return fmt.Errorf("error in severity rule #%d: %w", i, err)
2530
}

pkg/config/severity_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ func TestSeverity_Validate_error(t *testing.T) {
7979
},
8080
expected: "error in severity rule #0: severity should be set",
8181
},
82+
{
83+
desc: "same severity between default and rule",
84+
severity: &Severity{
85+
Default: "high",
86+
Rules: []SeverityRule{
87+
{
88+
Severity: "high",
89+
BaseRule: BaseRule{
90+
Path: "test",
91+
},
92+
},
93+
},
94+
},
95+
expected: `error in severity rule #0: the default severity ("high") is the same as the rule severity, this rule can be removed`,
96+
},
8297
}
8398

8499
for _, test := range testCases {

0 commit comments

Comments
 (0)