{"record":{"id":"dfe0ff3fa3ea9e4f","repo":"golangci/golangci-lint","slug":"invalid-source-regex-w","errorCode":null,"errorMessage":"invalid source regex: %w","messagePattern":"invalid source regex: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/base_rule.go","lineNumber":34,"sourceCode":"\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\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","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/base_rule.go#L16-L52","documentation":"Validation guard in BaseRule.Validate: the 'source' field of a rule is set but failed to compile as a regular expression. validateOptionalRegex rejects the rule before it can be used for filtering issues; the regex compile error is preserved via %w.","triggerScenarios":"An exclusion/inclusion rule sets `source` to a pattern Go's regexp package cannot compile — syntax errors or RE2-unsupported features like lookbehinds and backreferences.","commonSituations":"Reusing PCRE-style source filters from other linters; regexes with `(?<=...)` lookbehinds; escaping mistakes in YAML double-quoted strings.","solutions":["Fix the `source` regex to valid Go RE2 syntax","Rewrite lookbehind/backreference patterns using RE2-compatible constructs","Prefer single-quoted YAML scalars for regexes to avoid backslash mangling","Validate the pattern compiles with Go's regexp before committing config"],"exampleFix":"# before\nsource: \"(?<=foo)bar\"\n# after\nsource: 'foobar'","handlingStrategy":"validation","validationCode":"func checkSourceRegex(pattern string) error {\n\tif pattern == \"\" {\n\t\treturn nil\n\t}\n\t_, err := regexp.Compile(pattern)\n\treturn err\n}\n// before running: checkSourceRegex(rule.Source)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rewrite lookbehind patterns (`(?<=...)`) in RE2-compatible form","Compile all source patterns in tests to catch breakage early","Quote regexes with single quotes in YAML","Consult Go regexp docs (RE2) for supported syntax before writing patterns"],"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"}