Prefer String.raw for string literals that contain escaped backslashes.
This mirrors Sonar rule typescript:S7780.
| Property | Value |
|---|---|
| Type | suggestion |
| Fixable | Yes (--fix) |
| Recommended | warn |
| Strict | error |
Strings containing escaped backslashes are harder to read and easier to get wrong. Using String.raw avoids double escaping and keeps path-like and regex-source text easier to maintain.
const path = String.raw`C:\Users\dev\repo`;
const regexSource = String.raw`\d+\w+`;const path = 'C:\\Users\\dev\\repo';
const regexSource = '\\d+\\w+';This rule has no options:
'zero-tolerance/prefer-string-raw': 'error'Autofix rewrites eligible string literals to String.raw\`form. It intentionally skips unsafe cases such as literals containing template interpolation markers (for example,${...}`) or backticks.