RegExp is given a malformed pattern or unknown flags as literals, which throws

tx0/ts:regexp-bad-argumentdefaulterrorbug

What it finds

new RegExp("(\\d+"), RegExp("x", "gg"), new RegExp(".", "q"): the pattern or the flags given to RegExp as string literals are malformed, so the call throws a SyntaxError when it runs. A literal regular expression with the same mistake would be rejected when the file is parsed; through RegExp it waits until that line runs.

Reported are unbalanced parentheses and brackets, quantifiers with nothing to repeat, unknown flags, flags given twice, and u together with v.

From the rule's source, regexp_bad_argument.rs.

Example from the rule's tests
const a = new RegExp("(\\d+");tx0 reports: the pattern given to RegExp is malformedconst b = RegExp("x", "gg");tx0 reports: the flag g is given twiceconst c = new RegExp(".", "q");tx0 reports: q is not a flag of regular expressionsconst d = new RegExp("a{2}", "gi");const e = new RegExp(String.raw`\d`);
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/ts:regexp-bad-argument" = "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/ts:regexp-bad-argument] reason="..."

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