{"record":{"id":"35a6f5f36d7cad51","repo":"golangci/golangci-lint","slug":"error-in-exclude-rule-d-w","errorCode":null,"errorMessage":"error in exclude rule #%d: %w","messagePattern":"error in exclude rule #(.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/linters_exclusions.go","lineNumber":35,"sourceCode":"\tExclusionPresetCommonFalsePositives = \"common-false-positives\"\n\tExclusionPresetLegacy               = \"legacy\"\n)\n\nconst excludeRuleMinConditionsCount = 2\n\ntype LinterExclusions struct {\n\tGenerated   string        `mapstructure:\"generated\"`\n\tWarnUnused  bool          `mapstructure:\"warn-unused\"`\n\tPresets     []string      `mapstructure:\"presets\"`\n\tRules       []ExcludeRule `mapstructure:\"rules\"`\n\tPaths       []string      `mapstructure:\"paths\"`\n\tPathsExcept []string      `mapstructure:\"paths-except\"`\n}\n\nfunc (e *LinterExclusions) Validate() error {\n\tfor i, rule := range e.Rules {\n\t\tif err := rule.Validate(); err != nil {\n\t\t\treturn fmt.Errorf(\"error in exclude rule #%d: %w\", i, err)\n\t\t}\n\t}\n\n\tallPresets := []string{\n\t\tExclusionPresetComments,\n\t\tExclusionPresetStdErrorHandling,\n\t\tExclusionPresetCommonFalsePositives,\n\t\tExclusionPresetLegacy,\n\t}\n\n\tfor _, preset := range e.Presets {\n\t\tif !slices.Contains(allPresets, preset) {\n\t\t\treturn fmt.Errorf(\"invalid preset: %s\", preset)\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/linters_exclusions.go#L17-L53","documentation":"LinterExclusions.Validate iterates linters.exclusions.rules and wraps any per-rule validation failure with 'error in exclude rule #%d', where #N is the zero-based index of the offending rule. It localizes which rule in the list is malformed; the wrapped inner error says what's wrong with it.","triggerScenarios":"Any exclusion rule failing its own Validate — e.g. too few conditions set, invalid regex in path/source/text, or a bad exclusion-preset reference within the rule.","commonSituations":"Large exclusion lists where a hand-added rule is incomplete; regexes with unbalanced parentheses; rules copied between configs missing fields.","solutions":["Look at rule index #N (0-based) in linters.exclusions.rules and read the wrapped cause","Fix the inner issue: add missing conditions or correct the regex","Validate the config with 'golangci-lint config verify' before running"],"exampleFix":"# before (rule #1 has no second condition)\n  exclusions:\n    rules:\n      - path: _test\\.go\n      - text: 'unused'\n# after\n  exclusions:\n    rules:\n      - path: _test\\.go\n      - text: 'unused'\n        linters:\n          - staticcheck","handlingStrategy":"validation","validationCode":"for i, rule := range cfg.Linters.Exclusions.Rules {\n\tif err := rule.Validate(); err != nil {\n\t\treturn fmt.Errorf(\"exclusion rule #%d: %w\", i, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Linters.Exclusions.Validate(); err != nil {\n\tvar idxErr interface{ Error() string }\n\t// parse \"#N\" from message or pre-validate per-rule to get the index\n\tlog.Fatalf(\"%v\", err)\n}","preventionTips":["Pre-validate each exclusion rule individually to get precise indexes","Keep exclusion lists small and reviewed","Run 'golangci-lint config verify' before running lint"],"tags":["golangci-lint","config-validation","exclusions"],"backgroundTag":"invalid-exclusion-rule","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}