Open
Description
Information:
- ESLint version: 9.25.1
eslint-plugin-regexp
version: 2.7.0
Description
After updating transient dependencies, I noticed new violations of regexp/no-empty-alternative
and regexp/prefer-character-class
rules.
This was related to updating @eslint-community/eslint-utils
from 4.6.1 to 4.7.0. Both versions are within the dependency range:
eslint-plugin-regexp/package.json
Line 122 in 14ac3d8
This upstream PR looks relevant: eslint-community/eslint-utils#255
Here is an MWE:
const a = ["x", "y"] as const;
const b = ["x", "y", ""] as const;
const c = ["x", "y", "z"] as const;
const r1 = new RegExp(`^(${a.join("|")})$`);
const r2 = new RegExp(`^(${b.join("|")})$`);
const r3 = new RegExp(`^(${c.join("|")})$`);
Before @eslint-community/eslint-utils
was updated, no errors were triggered for the above code. But now I see this:
const r1 = new RegExp(`^(${a.join("|")})$`);
const r2 = new RegExp(`^(${b.join("|")})$`); // This empty alternative might be a mistake. If not, use a quantifier instead. eslint(regexp/no-empty-alternative)
const r3 = new RegExp(`^(${c.join("|")})$`); // Unexpected the disjunction of single element alternatives. Use character class '[...]' instead. eslint(regexp/prefer-character-class)
I believe that these are false positives. If a RegExp is built from the variables, it is impossible to meet the rules without introducing multiple sources of truth.