{"record":{"id":"582cdd3c9b4d49ba","repo":"golangci/golangci-lint","slug":"path-and-path-except-should-not-be-set-at-the-same","errorCode":null,"errorMessage":"path and path-except should not be set at the same time","messagePattern":"path and path-except should not be set at the same time","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/base_rule.go","lineNumber":38,"sourceCode":"func (b *BaseRule) Validate(minConditionsCount int) error {\n\tif err := validateOptionalRegex(b.Path); err != nil {\n\t\treturn fmt.Errorf(\"invalid path regex: %w\", err)\n\t}\n\n\tif err := validateOptionalRegex(b.PathExcept); err != nil {\n\t\treturn fmt.Errorf(\"invalid path-except regex: %w\", err)\n\t}\n\n\tif err := validateOptionalRegex(b.Text); err != nil {\n\t\treturn fmt.Errorf(\"invalid text regex: %w\", err)\n\t}\n\n\tif err := validateOptionalRegex(b.Source); err != nil {\n\t\treturn fmt.Errorf(\"invalid source regex: %w\", err)\n\t}\n\n\tif b.Path != \"\" && b.PathExcept != \"\" {\n\t\treturn errors.New(\"path and path-except should not be set at the same time\")\n\t}\n\n\tnonBlank := 0\n\tif len(b.Linters) > 0 {\n\t\tnonBlank++\n\t}\n\n\t// Filtering by path counts as one condition, regardless how it is done (one or both).\n\t// Otherwise, a rule with Path and PathExcept set would pass validation\n\t// whereas before the introduction of path-except that wouldn't have been precise enough.\n\tif b.Path != \"\" || b.PathExcept != \"\" {\n\t\tnonBlank++\n\t}\n\n\tif b.Text != \"\" {\n\t\tnonBlank++\n\t}\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/base_rule.go#L20-L56","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Delete one of the two keys from the rule, keeping only `path` or `path-except`.","If you need both behaviors, split them into two separate rules."],"exampleFix":"# before\nexclusions:\n  rules:\n    - path: _test\\.go\n      path-except: integration_test\\.go\n\n# after\nexclusions:\n  rules:\n    - path: _test\\.go","handlingStrategy":"validation","validationCode":"for (const rule of cfg.exclusions?.rules ?? []) {\n  if (rule.path && rule['path-except']) {\n    throw new Error(`Rule sets both path and path-except: ${JSON.stringify(rule)}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide per rule whether it is an include (`path`) or exclude (`path-except`) matcher.","Lint your YAML with `golangci-lint config verify` in CI.","Avoid blind YAML-merge tooling over exclusion rules."],"tags":["configuration","validation","yaml"],"backgroundTag":"mutually-exclusive-config-options","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}