Skip to content

Commit 599e578

Browse files
Added more docs for no-octal (#114)
* Added more docs for `no-octal` * Typo
1 parent b489266 commit 599e578

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docs/rules/no-octal.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ since: "v0.1.0"
1313

1414
## :book: Rule Details
1515

16-
This rule reports octal escape.
16+
This rule reports octal escapes.
1717

18-
`\0` is matches a `NUL` character. Do not follow this with another digit, because a 0 followed by a number is an octal escape sequence.
18+
`\0` matches the `NUL` character. However, if `\0` is followed by another digit, it will become an octal escape sequence (e.g. `\07`).
19+
20+
Octal escapes can also easily be confused with backreferences. The same character sequence (e.g. `\3`) can either escape a character or be a backreference depending on the number of capturing groups in the pattern. E.g. the `\2` in `/(a)\2/` is a character but the `\2` in `/(a)(b)\2/` is a backreference. This can be a problem when refactoring regular expressions because an octal escape can become a backreference or vice versa.
1921

2022
<eslint-code-block>
2123

@@ -25,9 +27,11 @@ This rule reports octal escape.
2527
/* ✓ GOOD */
2628
var foo = /\0/;
2729
var foo = /=/;
30+
var foo = /(a)\1/;
2831

2932
/* ✗ BAD */
3033
var foo = /\075/;
34+
var foo = /\1/;
3135
```
3236

3337
</eslint-code-block>

0 commit comments

Comments
 (0)