{"record":{"id":"2292b4090d9a750c","repo":"golangci/golangci-lint","slug":"can-t-set-severity-rule-option-no-default-severit","errorCode":null,"errorMessage":"can't set severity rule option: no default severity defined","messagePattern":"can't set severity rule option: no default severity defined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/severity.go","lineNumber":17,"sourceCode":"package config\n\nimport (\n\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 == \"\" {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/severity.go#L1-L35","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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"],"exampleFix":"// before (.golangci.yml)\nseverity:\n  rules:\n    - text: \"unused\"\n      severity: warning\n\n// after\nseverity:\n  default: error\n  rules:\n    - text: \"unused\"\n      severity: warning","handlingStrategy":"validation","validationCode":"if cfg.Severity != nil && len(cfg.Severity.Rules) > 0 && cfg.Severity.Default == \"\" {\n    return fmt.Errorf(\"severity rules defined but 'default' severity is missing\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"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"}