Use one character class consistently whenever all characters have to be matched.
configuration in plugin:clean-regex/recommended
: "warn"
There are multiple ways to create a character class which matches all characters. This rule can be used to enforce one consistent way to do that.
/[\s\S]/ -> /[\s\S]/
/[\d\D]/ -> /[\s\S]/
/[\D\w]/ -> /[\s\S]/
/[^]/ -> /[\s\S]/
/[\0-\uFFFF]/ -> /[\s\S]/
By default all match-all character classes will be replaced with [\s\S]
. To
change that you can set the charClass
option to the replacement string.
/[\s\S]/ -> /[^]/
/[\d\D]/ -> /[^]/
/[\D\w]/ -> /[^]/
/[^]/ -> /[^]/
/[\0-\uFFFF]/ -> /[^]/
The replacement mode will determine how this rule will replace match-all character classes and sets.
This is the default mode. It will replace all match-all character classes with
charClass
if the s
flag is not present. If the s
flag is present, all
match-all character classes will be replaced with a dot.
// (with charClass: "[^]")
/[\s\S]/ -> /[^]/
/[\s\S]/s -> /./s
/./s -> /./s
In this mode, all match-all character classes and sets will be replaced with
charClass
.
If the s
flag is present, it will be removed.
// (with charClass: "[^]")
/[\s\S]/ -> /[^]/
/[\s\S]/s -> /[^]/
/./s -> /[^]/
In this mode, all match-all character classes and sets will be replaced with a
dot. (The charClass
options won't be used.)
If the s
flag is not present, it will be added.
/[\s\S]/ -> /./s
/[\s\S]/s -> /./s
/./s -> /./s