{"record":{"id":"752241f7a458c295","repo":"golangci/golangci-lint","slug":"error-in-severity-rule-d-w","errorCode":null,"errorMessage":"error in severity rule #%d: %w","messagePattern":"error in severity rule #(.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/severity.go","lineNumber":22,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n)\n\nconst severityRuleMinConditionsCount = 1\n\ntype Severity struct {\n\tDefault string         `mapstructure:\"default\"`\n\tRules   []SeverityRule `mapstructure:\"rules\"`\n}\n\nfunc (s *Severity) Validate() error {\n\tif len(s.Rules) > 0 && s.Default == \"\" {\n\t\treturn errors.New(\"can't set severity rule option: no default severity defined\")\n\t}\n\n\tfor i, rule := range s.Rules {\n\t\tif err := rule.Validate(); err != nil {\n\t\t\treturn fmt.Errorf(\"error in severity rule #%d: %w\", i, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\ntype SeverityRule struct {\n\tBaseRule `mapstructure:\",squash\"`\n\tSeverity string `mapstructure:\"severity\"`\n}\n\nfunc (s *SeverityRule) Validate() error {\n\tif s.Severity == \"\" {\n\t\treturn errors.New(\"severity should be set\")\n\t}\n\n\treturn s.BaseRule.Validate(severityRuleMinConditionsCount)\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/severity.go#L4-L40","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Read the wrapped %w error to see which field of rule #%d is wrong and fix that rule in severity.rules","Ensure every rule sets both 'linternames' (list of linters) and 'severity' (one of the allowed severity strings)","Remove empty/placeholder entries from the rules list"],"exampleFix":"# before\nseverity:\n  default-severity: warning\n  rules:\n    - linternames: [errcheck]\n# after\nseverity:\n  default-severity: warning\n  rules:\n    - linternames: [errcheck]\n      severity: error","handlingStrategy":"validation","validationCode":"for i, rule := range cfg.Severity.Rules {\n  if len(rule.LinterNames) == 0 || rule.Severity == \"\" {\n    return fmt.Errorf(\"severity rule #%d needs linternames and severity\", i)\n  }\n}\nif len(cfg.Severity.Rules) > 0 && cfg.Severity.Default == \"\" {\n  return fmt.Errorf(\"severity rules require default-severity\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set default-severity when defining rules","Give each rule both linternames and severity","Remove empty YAML list items; validate config before CI"],"tags":["config","validation","severity-rules"],"backgroundTag":"invalid-config-value","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}