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

  1. Add a 'severity' key with a valid value to each severity rule
  2. Check the reported rule index (#N) in the wrapped message to find the offending rule
  3. Fix typos in the severity key (mapstructure ignores unknown keys silently)
  4. 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

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


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/d7ee4a0fd99fff4f. Report an issue: GitHub.