{"record":{"id":"d4a5585c316a30a0","repo":"golangci/golangci-lint","slug":"invalid-text-regex-w","errorCode":null,"errorMessage":"invalid text regex: %w","messagePattern":"invalid text regex: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/base_rule.go","lineNumber":30,"sourceCode":"\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\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.","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/config/base_rule.go#L12-L48","documentation":"BaseRule.Validate compiles the Text pattern (used to match issue text) via validateOptionalRegex. An invalid regex fails validation with this wrapped error, preventing the linter from starting with a broken rule.","triggerScenarios":"An exclusion/inclusion rule sets `text` to a pattern that Go's regexp cannot compile — invalid syntax, dangling quantifier, or unsupported constructs (backreferences, lookarounds).","commonSituations":"Matching lint messages copied from other tools' PCRE syntax; unescaped special characters like `(` or `+` intended literally; regexes written for grep -P.","solutions":["Fix the `text` regex to valid Go RE2 syntax","Escape literal metacharacters (`\\(`, `\\+`) that were meant literally","Use single-quoted YAML strings to keep backslashes intact","Paste the pattern into a Go-compatible regex tester to confirm it compiles"],"exampleFix":"# before\ntext: \"undeclared name: (foo|bar\"\n# after\ntext: \"undeclared name: (foo|bar)\"","handlingStrategy":"validation","validationCode":"func checkTextRegex(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: checkTextRegex(rule.Text)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Escape literal regex metacharacters in text patterns","Avoid PCRE-only features when copying message filters from other tools","Unit-test rule configs by compiling all patterns at startup","Use single-quoted YAML strings for regex values"],"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"}