golangci/golangci-lint · error

error in severity rule #%d: %w

Error message

error in severity rule #%d: %w

What it means

This error is a wrapper thrown by Severity.Validate() when one of the severity rules fails its own Validate(). The %w preserves the underlying rule error (e.g. a missing linternames or severity field) and #%d gives the zero-based index of the offending rule in severity.rules. A severity rule requires at least 'linternames' and 'severity' keys.

Source

Thrown at pkg/config/severity.go:22

	"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 == "" {
		return errors.New("severity should be set")
	}

	return s.BaseRule.Validate(severityRuleMinConditionsCount)
}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Read the wrapped %w error to see which field of rule #%d is wrong and fix that rule in severity.rules
  2. Ensure every rule sets both 'linternames' (list of linters) and 'severity' (one of the allowed severity strings)
  3. Remove empty/placeholder entries from the rules list

Example fix

# before
severity:
  default-severity: warning
  rules:
    - linternames: [errcheck]
# after
severity:
  default-severity: warning
  rules:
    - linternames: [errcheck]
      severity: error
Defensive patterns

Strategy: validation

Validate before calling

for i, rule := range cfg.Severity.Rules {
  if len(rule.LinterNames) == 0 || rule.Severity == "" {
    return fmt.Errorf("severity rule #%d needs linternames and severity", i)
  }
}
if len(cfg.Severity.Rules) > 0 && cfg.Severity.Default == "" {
  return fmt.Errorf("severity rules require default-severity")
}

Prevention

When it happens

Trigger: Configuring severity.rules where the i-th rule is structurally invalid — e.g. missing 'severity', missing 'linternames', or an empty rule map — then running golangci-lint or Severity.Validate().

Common situations: YAML list entries missing required keys; writing 'linter' instead of 'linternames'; empty dash items '- ' accidentally left in the rules list; rule structs built programmatically with zero values.

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/752241f7a458c295. Report an issue: GitHub.