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

  1. Fix the `path-except` regex to valid Go RE2 syntax
  2. Remember path-except is a regex, not a glob — convert `**/*.go` to `.*\.go$`
  3. Use single-quoted YAML strings to preserve backslashes
  4. 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

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


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/93c8165afe98d1eb. Report an issue: GitHub.