Skip to content

Commit

Permalink
fix: rule severity should be different than the default one
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 8, 2024
1 parent a23a896 commit 8aac3d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/config/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (s *Severity) Validate() error {
}

for i, rule := range s.Rules {
if s.Default == rule.Severity {
return fmt.Errorf("error in severity rule #%d: the default severity (%q) is the same as the rule severity, this rule can be removed",
i, s.Default)
}

if err := rule.Validate(); err != nil {
return fmt.Errorf("error in severity rule #%d: %w", i, err)
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/config/severity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ func TestSeverity_Validate_error(t *testing.T) {
},
expected: "error in severity rule #0: severity should be set",
},
{
desc: "same severity between default and rule",
severity: &Severity{
Default: "high",
Rules: []SeverityRule{
{
Severity: "high",
BaseRule: BaseRule{
Path: "test",
},
},
},
},
expected: `error in severity rule #0: the default severity ("high") is the same as the rule severity, this rule can be removed`,
},
}

for _, test := range testCases {
Expand Down

0 comments on commit 8aac3d1

Please sign in to comment.