golangci/golangci-lint · error

path and path-except should not be set at the same time

Error message

path and path-except should not be set at the same time

What it means

BaseRule.Validate enforces that an exclude-rule (or similar base rule) defines either `path` (include paths) or `path-except` (exclude paths), not both — the two matching modes are mutually exclusive. Both being non-empty makes the rule ambiguous, so validation fails.

Source

Thrown at pkg/config/base_rule.go:38

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++
	}

	// 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++
	}

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Delete one of the two keys from the rule, keeping only `path` or `path-except`.
  2. If you need both behaviors, split them into two separate rules.

Example fix

# before
exclusions:
  rules:
    - path: _test\.go
      path-except: integration_test\.go

# after
exclusions:
  rules:
    - path: _test\.go
Defensive patterns

Strategy: validation

Validate before calling

for (const rule of cfg.exclusions?.rules ?? []) {
  if (rule.path && rule['path-except']) {
    throw new Error(`Rule sets both path and path-except: ${JSON.stringify(rule)}`);
  }
}

Prevention

When it happens

Trigger: A .golangci.yml exclude-rules/exclusion entry with both `path:` and `path-except:` regex keys set to non-empty values, triggering Validate during config parsing.

Common situations: Merging config fragments where one adds `path` and another adds `path-except` to the same rule; migrating from v1 config syntax and keeping both keys.

Related errors


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