golangci/golangci-lint · error
invalid path-except regex: %w
Error message
invalid path-except regex: %w
What it means
Validation guard in BaseRule.Validate: the 'path-except' field of an exclusion/presets rule is set but is not a valid regular expression (compile failed). The rule cannot be applied, so validation fails; the compile error is wrapped with %w.
Source
Thrown at pkg/config/base_rule.go:26
type BaseRule struct {
Linters []string `mapstructure:"linters"`
Path string `mapstructure:"path"`
PathExcept string `mapstructure:"path-except"`
Text string `mapstructure:"text"`
Source string `mapstructure:"source"`
// For compatibility with exclude-use-default/include.
InternalReference string `mapstructure:"-"`
}
func (b *BaseRule) Validate(minConditionsCount int) error {
if err := validateOptionalRegex(b.Path); err != nil {
return fmt.Errorf("invalid path regex: %w", err)
}
if err := validateOptionalRegex(b.PathExcept); err != nil {
return fmt.Errorf("invalid path-except regex: %w", err)
}
if err := validateOptionalRegex(b.Text); err != nil {
return fmt.Errorf("invalid text regex: %w", err)
}
if err := validateOptionalRegex(b.Source); err != nil {
return fmt.Errorf("invalid source regex: %w", err)
}
if b.Path != "" && b.PathExcept != "" {
return errors.New("path and path-except should not be set at the same time")
}
nonBlank := 0
if len(b.Linters) > 0 {
nonBlank++
}View on GitHub (pinned to ed7a235d2d)
Solutions
- Fix the `path-except` regex to valid Go RE2 syntax
- Remember path-except is a regex, not a glob — convert `**/*.go` to `.*\.go$`
- Use single-quoted YAML strings to preserve backslashes
- Test the pattern in a Go regex validator before adding it to config
Example fix
# before path-except: "**/*_test.go" # after path-except: '_test\.go$'
Defensive patterns
Strategy: validation
Validate before calling
func checkPathExcept(pattern string) error {
if pattern == "" {
return nil
}
if strings.Contains(pattern, "**") {
return fmt.Errorf("path-except is a regex, not a glob: %q", pattern)
}
_, err := regexp.Compile(pattern)
return err
} Prevention
- Treat path-except as a regex, never a glob
- Test patterns with Go regexp before adding to config
- Prefer single-quoted YAML scalars to preserve backslashes
- Split complex patterns into path + path-except pairs
When it happens
Trigger: A `path-except` value in an exclusion/inclusion rule is not a valid Go regexp: unbalanced constructs, bad escapes, or unsupported features like backreferences or lookarounds.
Common situations: Writing path-except as a glob (`**/*.go`) instead of a regex; using JS-style negative lookahead; YAML double-quote escaping removing backslashes.
Related errors
- invalid path regex: %w
- invalid text regex: %w
- invalid source regex: %w
- the configuration contains invalid elements
- the configuration contains invalid elements
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/93c8165afe98d1eb.
Report an issue: GitHub.