Skip to content

Latest commit

 

History

History
52 lines (34 loc) · 1.51 KB

no-octal.md

File metadata and controls

52 lines (34 loc) · 1.51 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-octal
disallow octal escape sequence
v0.1.0

regexp/no-octal

💡 This rule is manually fixable by editor suggestions.

disallow octal escape sequence

📖 Rule Details

This rule reports octal escapes.

\0 matches the NUL character. However, if \0 is followed by another digit, it will become an octal escape sequence (e.g. \07).

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.

/* eslint regexp/no-octal: "error" */

/* ✓ GOOD */
var foo = /\0/;
var foo = /=/;
var foo = /(a)\1/;

/* ✗ BAD */
var foo = /\075/;
var foo = /\1/;

🔧 Options

Nothing.

🚀 Version

This rule was introduced in eslint-plugin-regexp v0.1.0

🔍 Implementation