Skip to content

Latest commit

 

History

History
61 lines (38 loc) · 1.6 KB

no-standalone-backslash.md

File metadata and controls

61 lines (38 loc) · 1.6 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-standalone-backslash
disallow standalone backslashes (`\`)
v0.10.0

regexp/no-standalone-backslash

disallow standalone backslashes (\)

📖 Rule Details

This rule disallows backslash (\) without escape.

E.g. the regular expression /\c/ without the unicode (u) flag is the same pattern as /\\c/.

In most cases, standalone backslashes are used by accident when a control escape sequence (\cX) or another escape sequence was intended. They are very confusing and should not be used intentionally.

This behavior is described in Annex B of the ECMAScript specification.

/* eslint regexp/no-standalone-backslash: "error" */

/* ✓ GOOD */
var foo = /\cX/;

/* ✗ BAD */
var foo = /\c/;
var foo = /\c-/;
var foo = /[\c]/;

🔧 Options

Nothing.

👫 Related rules

📚 Further reading

🚀 Version

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

🔍 Implementation