An issue is raised when a string literal contains escaped backslashes (\\) that could be simplified using String.raw template literals.

Why is this an issue?

String literals with escaped backslashes can be difficult to read and maintain. Each backslash character must be escaped with another backslash, creating sequences like \\ that are hard to interpret at a glance.

This problem is particularly common when working with:

The String.raw template literal provides a cleaner alternative. It treats backslashes literally without requiring escaping, making the code more readable and less error-prone. The intent becomes clearer, and there’s less chance of accidentally missing or adding extra backslashes during maintenance.

What is the potential impact?

Using escaped backslashes instead of String.raw reduces code readability and increases the likelihood of errors when maintaining string literals. While this doesn’t cause runtime issues, it makes the codebase harder to understand and modify correctly.

How to fix?

Replace string literals containing escaped backslashes with String.raw template literals. The backslashes inside the template literal don’t need to be escaped.

Non-compliant code example

const filePath = "C:\\Users\\Documents\\file.txt"; // Noncompliant

Compliant code example

const filePath = String.raw`C:\Users\Documents\file.txt`;

Documentation