You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this option, only trivial cases will be reported. This means that the reported alternative can be removed without affecting the pattern.
57
60
58
-
/* ✓ GOOD */
59
-
var foo =/a|b/
60
-
var foo =/(a|b)/
61
-
var foo =/(?:a|b)/
61
+
Trivial cases include duplicates (e.g. `a|a`) and subsets (e.g. `\w|a`).
62
62
63
-
/* ✗ BAD */
63
+
-`report: "interesting"`
64
64
65
-
// Duplication
66
-
var foo =/a|a/
65
+
All trivial cases and superset cases will be reported.
67
66
68
-
// A string that matches the pattern on the right also matches the pattern on the left, so it doesn't make sense to process the pattern on the right.
69
-
var foo =/a|abc/
70
-
var foo =/.|abc/
71
-
var foo =/.|a|b|c/
72
-
```
67
+
In superset cases, an alternative _might_ be removable. Whether a reported alternative is removable cannot trivially be decided and depends on the pattern.
73
68
74
-
</eslint-code-block>
69
+
E.g. `Foo|\w+` is a superset case because `\w+` is a superset of `Foo`. In the regex `/\b(?:Foo|\w+)\b/`, the `Foo` alternative can be removed. However in the regex `/Foo|\w+/`, the `Foo` alternative cannot be removed without affecting the pattern.
70
+
71
+
Whether a reported alternative is removable has to be decided by the developer.
72
+
73
+
-`report: "all"`
74
+
75
+
All cases of duplication and partial duplication (overlap) will be reported.
76
+
77
+
Partial duplication (overlap) is typically not harmful and difficult to remove. E.g. the harmless overlap of `a.*|.*b` is `a.*b`.
78
+
79
+
Partial duplication is only harmful if it occurs within a quantifier because then it can cause exponential backtracking. By default, this rule will try to report all cases of potential exponential backtracking.
80
+
81
+
However, the rule might not be able to detect that overlap happens within a quantifier if the regex was constructed at runtime. Example:
If your codebase contained many such partial regexes, then reporting all cases might yield cases that could not be identified as causing exponential backtracking.
If set to `true`, then this rule will always report partial duplications that can cause exponential backtracking. This option is set to `true` by default.
93
+
94
+
Only set this option to `false` if you have some other mean to reliably detect exponential backtracking.
0 commit comments