golangci/golangci-lint · error
at least %d of (text, source, path[-except], linters) should
Error message
at least %d of (text, source, path[-except], linters) should be set
What it means
BaseRule.Validate requires a linter-exclusion rule to set at least minConditionsCount (typically 2) of the fields: text, source, path/path-except, and linters. This prevents overly broad exclusion rules that would silently disable linting for too much code. If fewer fields are non-blank, the rule is considered too vague and validation fails.
Source
Thrown at pkg/config/base_rule.go:62
}
// Filtering by path counts as one condition, regardless how it is done (one or both).
// Otherwise, a rule with Path and PathExcept set would pass validation
// whereas before the introduction of path-except that wouldn't have been precise enough.
if b.Path != "" || b.PathExcept != "" {
nonBlank++
}
if b.Text != "" {
nonBlank++
}
if b.Source != "" {
nonBlank++
}
if nonBlank < minConditionsCount {
return fmt.Errorf("at least %d of (text, source, path[-except], linters) should be set", minConditionsCount)
}
return nil
}
func validateOptionalRegex(value string) error {
if value == "" {
return nil
}
_, err := regexp.Compile(value)
return err
}
View on GitHub (pinned to ed7a235d2d)
Solutions
- Add a second condition to the rule, most commonly a 'linters' list naming the linters the exclusion applies to
- If the exclusion is unconditional, remove the rule entirely — a rule with fewer than 2 conditions is too broad
- Check field names for typos (path-except vs pathExcept) that leave fields blank
Example fix
# before
linters:
exclusions:
rules:
- text: 'missing doc comment'
# after
linters:
exclusions:
rules:
- text: 'missing doc comment'
linters:
- revive Defensive patterns
Strategy: validation
Validate before calling
for _, r := range cfg.Linters.Exclusions.Rules {
cond := 0
if r.Text != "" { cond++ }
if r.Source != "" { cond++ }
if len(r.Path) > 0 || len(r.PathsExcept) > 0 { cond++ }
if len(r.Linters) > 0 { cond++ }
if cond < 2 { return fmt.Errorf("exclusion rule needs >=2 conditions: %+v", r) }
} Try / catch
err := cfg.Validate(); if err != nil { log.Fatalf("invalid config: %v", err) } Prevention
- Always pair 'text' or 'source' with a 'linters' list in exclusion rules
- Run 'golangci-lint config verify' in CI before linting
- Never delete the 'linters' key when copying exclusion examples
When it happens
Trigger: Running golangci-lint with a config whose linters.exclusions.rules entry has fewer than 2 of (text, source, path[-except], linters) set, e.g. a rule with only 'text' and no 'linters' or 'path'.
Common situations: Hand-editing the YAML config and adding an exclusion rule with only a message regex; copying a rule from docs and dropping the 'linters' key; typos like 'path-exept' leaving path unset.
Related errors
- error in exclude rule #%d: %w
- %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/1a4d1c8385c13c94.
Report an issue: GitHub.