Disallow unnecessary character classes.
configuration in plugin:clean-regex/recommended
: "warn"
Unnecessary character classes contain only one character and can be trivially
removed. E.g. [a]
, [\x61]
, [\?]
.
Sometimes characters have to be escaped, in order to remove the character class
(e.g. a[+]
-> a\+
). The automatic escaping can be disabled by using
{ avoidEscape: true }
in the rule configuration.
Note: This option does not affect characters already escaped in the character
class (e.g. a[\+]
-> a\+
).
Note: \b
means backspace (\x08
) inside of character classes but it will
interpreted as a boundary assertion anywhere else, so it will be escaped as
\x08
.
/a[+]/ -> /a\+/
/a[.]/ -> /a\./
/[\b]/ -> /\x08/
/a[\s]/ -> /a\s/
/a[\+]/ -> /a\+/
/a[+]/ -> /a[+]/
/a[.]/ -> /a[.]/
/[\b]/ -> /[\b]/
/a[\s]/ -> /a\s/
/a[\+]/ -> /a\+/