Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to not override severity from linters #4452

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
ldez marked this conversation as resolved.
Show resolved Hide resolved
ldez marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading