Disallow assertions that are known to always accept (or reject).
configuration in plugin:clean-regex/recommended
: "error"
Some assertion are unnecessary because the rest of the pattern forces them to always be accept (or reject).
Examples of valid code for this rule:
/\bfoo\b/
Examples of invalid code for this rule:
/#\bfoo/ // \b will always accept
/foo\bbar/ // \b will always reject
/$foo/ // $ will always reject
/(?=\w)\d+/ // (?=\w) will always accept
Right now, this rule is implemented by only looking a single character ahead and
behind. This is enough to determine whether the builtin assertions (\b
, \B
,
^
, $
) trivially reject or accept but it is not enough for all lookarounds.
The algorithm determining the characters ahead and behind is very conservative
which can lead to false negatives.