An issue is raised when a string literal contains escaped backslashes (\\) that could be simplified using String.raw
template literals.
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.
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.
Replace string literals containing escaped backslashes with String.raw template literals. The backslashes inside the template literal
don’t need to be escaped.
const filePath = "C:\\Users\\Documents\\file.txt"; // Noncompliant
const filePath = String.raw`C:\Users\Documents\file.txt`;