golangci/golangci-lint · error
can't set severity rule option: no default severity defined
Error message
can't set severity rule option: no default severity defined
What it means
The severity configuration section (used by the severity-rules linter) requires a 'default' severity whenever any severity 'rules' are defined. golangci-lint throws this during config validation because without a default severity, rules that do not match would leave diagnostics with no assigned severity. It is thrown by Severity.Validate() before linting begins.
Source
Thrown at pkg/config/severity.go:17
package config
import (
"errors"
"fmt"
)
const severityRuleMinConditionsCount = 1
type Severity struct {
Default string `mapstructure:"default"`
Rules []SeverityRule `mapstructure:"rules"`
}
func (s *Severity) Validate() error {
if len(s.Rules) > 0 && s.Default == "" {
return errors.New("can't set severity rule option: no default severity defined")
}
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 == "" {View on GitHub (pinned to ed7a235d2d)
Solutions
- Add a 'default' severity option in the severity config section, e.g. severity: default: error
- For the legacy setting, set default-severity in severity-rules configuration
- If rules are unnecessary, remove the severity rules entries so validation passes
- Run golangci-lint config verify to confirm the severity section is well-formed
Example fix
// before (.golangci.yml)
severity:
rules:
- text: "unused"
severity: warning
// after
severity:
default: error
rules:
- text: "unused"
severity: warning Defensive patterns
Strategy: validation
Validate before calling
if cfg.Severity != nil && len(cfg.Severity.Rules) > 0 && cfg.Severity.Default == "" {
return fmt.Errorf("severity rules defined but 'default' severity is missing")
} Prevention
- Always pair severity rules with a default severity in the same config block
- Run 'golangci-lint config verify' in CI before linting
- When migrating from severity-rules, carry over default-severity
When it happens
Trigger: Config contains [severity.rules] entries (e.g. matching text or source patterns) but the [severity] (or severity-rules) section has no 'default' key set. Also triggered when rules exist via the deprecated 'severity-rules' setting without 'default-severity'.
Common situations: Users copy a severity-rules example from documentation or a blog post that only shows the rules, omitting default-severity; upgrading golangci-lint after the option moved into the severity section; YAML indentation mistakes that put rules under severity while default stays unset.
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
- severity should be set
- 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/2292b4090d9a750c.
Report an issue: GitHub.