A constant regular expression is not valid in Go's syntax

tx0/go:invalid-regexpdefaultwarningbug

What it finds

regexp.MustCompile("(?<=id=)\\d+"): Go's regular expressions use the RE2 syntax, which has no lookaround and no backreferences, and rejects patterns other engines accept. MustCompile then panics when the package is initialized, and Compile returns an error on every call.

The pattern must be a constant string of the file given to Compile, MustCompile, CompilePOSIX, MustCompilePOSIX, Match or MatchString of regexp, resolved through the imports. Reported are only problems that RE2 always rejects: unbalanced parentheses, an unterminated character class, a repetition with nothing to repeat or applied to another repetition, a repetition count above 1000 or with its bounds reversed, a range in a class whose ends are reversed, lookaround groups, and the escapes \1 to \9 and letters that RE2 does not define, such as \Z or \h.

From the rule's source, invalid_regexp.rs.

Example from the rule's tests
package p import "regexp" var (	id     = regexp.MustCompile(`(?<=id=)\d+`)tx0 reports: lookaround is not supported	word   = regexp.MustCompile(`^\w+$`)	pair   = regexp.MustCompile(`(a)\1`)tx0 reports: backreferences are not supported	open   = regexp.MustCompile("(ab")tx0 reports: a ( without a matching )	lazy   = regexp.MustCompile(`a+?b*?`)	named  = regexp.MustCompile(`(?P<year>\d{4})-(?i:x)`))
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/go:invalid-regexp" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:invalid-regexp] reason="..."

tx0 explain tx0/go:invalid-regexp shows the same in the terminal. Found a false positive? Report it.