{"record":{"id":"d7ee4a0fd99fff4f","repo":"golangci/golangci-lint","slug":"severity-should-be-set","errorCode":null,"errorMessage":"severity should be set","messagePattern":"severity should be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/severity.go","lineNumber":36,"sourceCode":"\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}\n","sourceCodeStart":18,"sourceCodeEnd":41,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/severity.go#L18-L41","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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"],"exampleFix":"// before (.golangci.yml)\nseverity:\n  default: error\n  rules:\n    - text: \"never use\"\n\n// after\nseverity:\n  default: error\n  rules:\n    - text: \"never use\"\n      severity: warning","handlingStrategy":"validation","validationCode":"valid := map[string]bool{\"error\": true, \"warning\": true, \"info\": true}\nfor i, r := range cfg.Severity.Rules {\n    if !valid[r.Severity] {\n        return fmt.Errorf(\"severity rule #%d: severity must be one of error|warning|info\", i)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["config","golangci-lint","severity","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}