golangci/golangci-lint · error
error in exclude rule #%d: %w
Error message
error in exclude rule #%d: %w
What it means
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.
Source
Thrown at pkg/config/linters_exclusions.go:35
ExclusionPresetCommonFalsePositives = "common-false-positives"
ExclusionPresetLegacy = "legacy"
)
const excludeRuleMinConditionsCount = 2
type LinterExclusions struct {
Generated string `mapstructure:"generated"`
WarnUnused bool `mapstructure:"warn-unused"`
Presets []string `mapstructure:"presets"`
Rules []ExcludeRule `mapstructure:"rules"`
Paths []string `mapstructure:"paths"`
PathsExcept []string `mapstructure:"paths-except"`
}
func (e *LinterExclusions) Validate() error {
for i, rule := range e.Rules {
if err := rule.Validate(); err != nil {
return fmt.Errorf("error in exclude rule #%d: %w", i, err)
}
}
allPresets := []string{
ExclusionPresetComments,
ExclusionPresetStdErrorHandling,
ExclusionPresetCommonFalsePositives,
ExclusionPresetLegacy,
}
for _, preset := range e.Presets {
if !slices.Contains(allPresets, preset) {
return fmt.Errorf("invalid preset: %s", preset)
}
}
return nil
}View on GitHub (pinned to ed7a235d2d)
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
Example fix
# before (rule #1 has no second condition)
exclusions:
rules:
- path: _test\.go
- text: 'unused'
# after
exclusions:
rules:
- path: _test\.go
- text: 'unused'
linters:
- staticcheck Defensive patterns
Strategy: validation
Validate before calling
for i, rule := range cfg.Linters.Exclusions.Rules {
if err := rule.Validate(); err != nil {
return fmt.Errorf("exclusion rule #%d: %w", i, err)
}
} Try / catch
if err := cfg.Linters.Exclusions.Validate(); err != nil {
var idxErr interface{ Error() string }
// parse "#N" from message or pre-validate per-rule to get the index
log.Fatalf("%v", err)
} Prevention
- Pre-validate each exclusion rule individually to get precise indexes
- Keep exclusion lists small and reviewed
- Run 'golangci-lint config verify' before running lint
When it happens
Trigger: 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.
Common situations: Large exclusion lists where a hand-added rule is incomplete; regexes with unbalanced parentheses; rules copied between configs missing fields.
Related errors
- at least %d of (text, source, path[-except], linters) should
- %s is not a formatter
- %s is a formatter
- invalid preset: %s
- custom linter %q: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/35a6f5f36d7cad51.
Report an issue: GitHub.