no-useless-escape
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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).
Example
Section titled “Example”{ "a": "x\ny\"z\\wA", "b": "p\/q", "c\/d": ["\/"]}Configuration
Section titled “Configuration”js: lint: rules: no-useless-escape: warn # off (default), warn, errorjson: lint: rules: no-useless-escape: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”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 |