pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
regexp/no-useless-set-operand |
disallow unnecessary elements in expression character classes |
v2.0.0-next.10 |
💼 This rule is enabled in the ✅ plugin:regexp/recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
disallow unnecessary elements in expression character classes
The v
flag added set operations for character classes, e.g. [\w&&\D]
and [\w--\d]
, but there are no limitations on what operands can be used. This rule reports any unnecessary operands.
/* eslint regexp/no-useless-set-operand: "error" */
/* ✓ GOOD */
foo = /[\w--\d]/v
foo = /[\w--[\d_]]/v
/* ✗ BAD */
foo = /[\w--[\d$]]/v
foo = /[\w&&\d]/v
foo = /[\w&&\s]/v
foo = /[\w&&[\d\s]]/v
foo = /[\w&&[^\d\s]]/v
foo = /[\w--\s]/v
foo = /[\d--\w]/v
foo = /[\w--[\d\s]]/v
foo = /[\w--[^\d\s]]/v
Nothing.
This rule was introduced in eslint-plugin-regexp v2.0.0-next.10