new RegExp is given a string literal where a regular expression literal says the same

tx0/ts:regexp-constructor-with-literalallwarningstyle/conventionsdepth faststyle

What it finds

A pattern known when the code is written reads better as a literal: it needs no double escaping of backslashes, and errors in it are reported when the file is parsed rather than when the line runs.

Reported are RegExp calls and new RegExp expressions whose pattern and flags are string literals.

From the rule's source, regexp_constructor_with_literal.rs.

Example from the rule's tests
export const digits = new RegExp("\\d+", "g");tx0 reports: this pattern is a literalexport function dynamic(p: string) {  return new RegExp(p);}
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 from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:regexp-constructor-with-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/ts:regexp-constructor-with-literal] reason="..."

tx0 explain tx0/ts:regexp-constructor-with-literal shows the same in the terminal. Found a false positive? Report it.