Skip to content

Prefer using the String.raw tag to avoid escaping \ ​

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

String.raw can be used to avoid escaping \.

Fail ​

js
const file = "C:\\windows\\style\\path\\to\\file.js";
js
const regexp = new RegExp('foo\\.bar');

Pass ​

js
const file = String.raw`C:\windows\style\path\to\file.js`;
js
const regexp = new RegExp(String.raw`foo\.bar`);

Released under the Apache License 2.0.