Skip to content

unicorn/prefer-string-raw Style

🛠️ An auto-fix is available for this rule.

What it does

Prefers use of String.raw to avoid escaping .

Why is this bad?

Excessive backslashes can make string values less readable which can be avoided by using String.raw.

Example

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/prefer-string-raw
json
{
  "rules": {
    "unicorn/prefer-string-raw": "error"
  }
}

References

Released under the MIT License.