golangci/golangci-lint · error
severity should be set
Error message
severity should be set
What it means
Each individual severity rule must declare which severity it assigns (e.g. error, warning, info). SeverityRule.Validate() throws this when a rule matches patterns but has no 'severity' key. The rule is otherwise unusable, so config validation fails early.
Source
Thrown at pkg/config/severity.go:36
}
for i, rule := range s.Rules {
if err := rule.Validate(); err != nil {
return fmt.Errorf("error in severity rule #%d: %w", i, err)
}
}
return nil
}
type SeverityRule struct {
BaseRule `mapstructure:",squash"`
Severity string `mapstructure:"severity"`
}
func (s *SeverityRule) Validate() error {
if s.Severity == "" {
return errors.New("severity should be set")
}
return s.BaseRule.Validate(severityRuleMinConditionsCount)
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Add a 'severity' key with a valid value to each severity rule
- Check the reported rule index (#N) in the wrapped message to find the offending rule
- Fix typos in the severity key (mapstructure ignores unknown keys silently)
- Remove the rule entirely if it does not need a severity override
Example fix
// before (.golangci.yml)
severity:
default: error
rules:
- text: "never use"
// after
severity:
default: error
rules:
- text: "never use"
severity: warning Defensive patterns
Strategy: validation
Validate before calling
valid := map[string]bool{"error": true, "warning": true, "info": true}
for i, r := range cfg.Severity.Rules {
if !valid[r.Severity] {
return fmt.Errorf("severity rule #%d: severity must be one of error|warning|info", i)
}
} Prevention
- Give every rule an explicit severity key
- Watch for typos like 'serverity' since unknown keys are ignored
- Lint your YAML schema with a schema validator for .golangci.yml
When it happens
Trigger: A [severity.rules] entry defines text/source/path matchers but omits the 'severity' option. Validation loops over rules and returns 'error in severity rule #N: severity should be set'.
Common situations: Copying rule snippets that only show matching options; typo'd key such as 'serverity' or 'severities'; renaming the severity field during migration and forgetting it on some rules.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- can't set severity rule option: no default severity defined
- the configuration contains invalid elements
- the configuration contains invalid elements
- enable-all and disable-all options must not be combined
- enable-all and enabled-tags options must not be combined
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/d7ee4a0fd99fff4f.
Report an issue: GitHub.