Skip to content

Commit

Permalink
feat: option to not override severity from linters (#4452)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Mar 4, 2024
1 parent f81c3f2 commit 3d91352
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,10 @@ severity:
# Default: false
case-sensitive: true

# Don't override severity defined by linters.
# Default: false
keep-linter-severity: true

# When a list of severity rules are provided, severity information will be added to lint issues.
# Severity rules have the same filtering capability as exclude rules
# except you are allowed to specify one matcher per severity rule.
Expand Down
7 changes: 4 additions & 3 deletions pkg/config/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
const severityRuleMinConditionsCount = 1

type Severity struct {
Default string `mapstructure:"default-severity"`
CaseSensitive bool `mapstructure:"case-sensitive"`
Rules []SeverityRule `mapstructure:"rules"`
Default string `mapstructure:"default-severity"`
CaseSensitive bool `mapstructure:"case-sensitive"`
Rules []SeverityRule `mapstructure:"rules"`
KeepLinterSeverity bool `mapstructure:"keep-linter-severity"` // TODO(ldez): in v2 should be changed to `Override`.
}

func (s *Severity) Validate() error {
Expand Down
1 change: 1 addition & 0 deletions pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func getSeverityRulesProcessor(cfg *config.Severity, log logutils.Log, files *fs
Default: cfg.Default,
Rules: severityRules,
CaseSensitive: cfg.CaseSensitive,
Override: !cfg.KeepLinterSeverity,
}

return processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, severityOpts)
Expand Down
7 changes: 7 additions & 0 deletions pkg/result/processors/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type SeverityOptions struct {
Default string
Rules []SeverityRule
CaseSensitive bool
Override bool
}

type Severity struct {
Expand All @@ -35,6 +36,7 @@ type Severity struct {

defaultSeverity string
rules []severityRule
override bool
}

func NewSeverity(log logutils.Log, files *fsutils.Files, opts SeverityOptions) *Severity {
Expand All @@ -43,6 +45,7 @@ func NewSeverity(log logutils.Log, files *fsutils.Files, opts SeverityOptions) *
files: files,
log: log,
defaultSeverity: opts.Default,
override: opts.Override,
}

prefix := "(?i)"
Expand All @@ -62,6 +65,10 @@ func (p *Severity) Process(issues []result.Issue) ([]result.Issue, error) {
}

return transformIssues(issues, func(i *result.Issue) *result.Issue {
if i.Severity != "" && !p.override {
return i
}

for _, rule := range p.rules {
rule := rule

Expand Down

0 comments on commit 3d91352

Please sign in to comment.