Skip to content

Commit dda117f

Browse files
Add docs for possible fixes for no-potentially-useless-backreference (#543)
* Add docs for possible fixes for `no-potentially-useless-backreference` * uuhhhwa * Lint
1 parent b97aeba commit dda117f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/rules/no-potentially-useless-backreference.md

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ var foo = /((a)|c)+b\2/;
3737

3838
</eslint-code-block>
3939

40+
### Possible fixes
41+
42+
_Note:_ Since this rule finds potential programming errors, there are no automatic fixes and suggestions. Fixing reports will always involve manually changing the regex. However, it is important to note that this rule reports _potential_ errors. If you are confident that a regex is correct, feel free to disable this rule for that regex.
43+
44+
One common pattern this rule reports is `/(a)?b\1/`. This typically happens when searching for optionally quoted text. While it is possible to move the `?` inside the capturing group, it is often better to explicitly factor out the `b` path: `/(a)b\1|b/`. Since quoted and unquoted text typically have slightly different syntax, this form encourages using the correct syntax for each case, resulting in more correct regexes.
45+
46+
Other patterns reported by this rule can typically also be fixed by factoring out the capturing group + backreference.
47+
4048
## :wrench: Options
4149

4250
Nothing.

0 commit comments

Comments
 (0)