{"record":{"id":"ed3142ac2dc10626","repo":"golangci/golangci-lint","slug":"invalid-path-regex-w","errorCode":null,"errorMessage":"invalid path regex: %w","messagePattern":"invalid path regex: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/base_rule.go","lineNumber":22,"sourceCode":"\t\"errors\"\n\t\"fmt\"\n\t\"regexp\"\n)\n\ntype BaseRule struct {\n\tLinters    []string `mapstructure:\"linters\"`\n\tPath       string   `mapstructure:\"path\"`\n\tPathExcept string   `mapstructure:\"path-except\"`\n\tText       string   `mapstructure:\"text\"`\n\tSource     string   `mapstructure:\"source\"`\n\n\t// For compatibility with exclude-use-default/include.\n\tInternalReference string `mapstructure:\"-\"`\n}\n\nfunc (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","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/base_rule.go#L4-L40","documentation":"BaseRule.Validate checks that rule conditions hold valid regular expressions. The Path (path) pattern of an exclude/include rule is compiled via validateOptionalRegex; an invalid Go regex fails validation with this wrapped error before the linter runs.","triggerScenarios":"Configuring `issues.exclude-rules` or `linters.exclusion-rules` (or presets referencing BaseRule) with a `path` value that is not a valid Go regexp — e.g. unbalanced parentheses, trailing `\\`, invalid `(?!...)` lookahead which Go RE2 does not support.","commonSituations":"Porting PCRE/JS-style regexes (lookaheads/lookbehinds) into Go config; typos like `[a-z` unclosed character class; escaping mistakes in YAML double-quoted strings.","solutions":["Fix the `path` regex so it compiles as Go RE2 syntax (test with regexp.Compile)","Replace lookaheads/lookbehinds with RE2-compatible alternatives (e.g. two rules, or `path-except`)","Quote regex carefully in YAML: prefer single quotes to avoid escape-eating by double quotes","Verify the pattern with `go run` / a RE2 playground before committing it"],"exampleFix":"# before\npath: \"(?!vendor).*\\\\.go$\"\n# after\npath: \"^(?!vendor/).*\\\\.go$\"  # invalid in RE2 — use instead:\n# path-except: '^vendor/.*\\.go$'","handlingStrategy":"validation","validationCode":"func checkRegex(field, pattern string) error {\n\tif pattern == \"\" {\n\t\treturn nil\n\t}\n\tif _, err := regexp.Compile(pattern); err != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", field, err)\n\t}\n\treturn nil\n}\n// before running: checkRegex(\"path\", rule.Path)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate every regex in config with Go's regexp.Compile in tests","Remember Go RE2 has no lookaheads/lookbehinds/backreferences","Use single-quoted YAML strings for regex patterns","Convert glob habits (`**`) into regex equivalents (`.*`)"],"tags":["golangci-lint","config","regex","validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}