A pattern contains [], a set that no character fits

tx0/ts:regex-never-matchesdefaultwarningbug

What it finds

/^[]$/, new RegExp("a[]b"): an empty character class matches no character at all, so the part of the pattern around it, and often the whole pattern, can never match. Usually the brackets were meant to be escaped, or characters were left out.

[^], which matches any character, is not empty and is left alone.

From the rule's source, regex_never_matches.rs.

Example from the rule's tests
const a = /^a[]b$/;tx0 reports: [] in this pattern matches no characterconst b = new RegExp("x[]");tx0 reports: [] in this pattern matches no characterconst c = /[^]/;const d = /\[\]/;const e = /[\]]/;
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:regex-never-matches" = "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:regex-never-matches] reason="..."

tx0 explain tx0/ts:regex-never-matches shows the same in the terminal. Found a false positive? Report it.