A regular expression is written in a quoted string with doubled backslashes
What it finds
regexp.MustCompile("\\d+\\.\\d+"): in a double-quoted string every backslash of the pattern is written twice, which makes the pattern hard to read and easy to get wrong. A raw string, ` \d+\.\d+ `, holds the pattern as it is.
Reported is a double-quoted literal that contains \\ given as the pattern to Compile, MustCompile, MatchString, Match, CompilePOSIX or MustCompilePOSIX of regexp, when the pattern has no backquote or line break that a raw string could not hold.
From the rule's source, escaped_regexp_literal.rs.
package p import "regexp" var version = regexp.MustCompile("\\d+\\.\\d+")tx0 reports: the pattern doubles its backslashes; a raw string holds it as it is var raw = regexp.MustCompile(`\d+`) Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:escaped-regexp-literal" = "warning"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:escaped-regexp-literal] reason="..."tx0 explain tx0/go:escaped-regexp-literal shows the same in the terminal. Found a false positive? Report it.