Skip to content

no-useless-escape

Reports a backslash before a character that needs no escape, in a string ('\d'), a template literal or a regex literal (/\-/, /\_/). Valid escapes (\n, \t, \\, \', \", \x41, \u0041, \0, a line continuation) are not reported, and neither are a \- in the middle of a character class (/[a\-z]/), \^ at the start of one and \/ in a regex literal.

In a string the useless backslash is dropped, so '\d' is the letter d, which is not what a reader who knows regex expects. In a regex it hides the characters that matter.

To fix, remove the backslash, or write the escape that is meant (\\d).

Reported
{
"a": "x\ny\"z\\wA",
"b": "p\/q",
"c\/d": ["\/"]
}
js:
lint:
rules:
no-useless-escape: warn # off (default), warn, error
json:
lint:
rules:
no-useless-escape: warn # off (default), warn, error

Enabled by the presets: json/eslint-plugin-jsonc-recommended, js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-useless-escape in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint no-useless-escape partial regex v flag classes are read like u classes
eslint-plugin-jsonc jsonc/no-useless-escape partial \/ counts as useless, as the plugin reports it