Skip to content

eslint/no-useless-escape Correctness

This rule is turned on by default.
🛠️ An auto-fix is available for this rule.

What it does

Disallow unnecessary escape characters

Why is this bad?

Example

Examples of incorrect code for this rule:

javascript
/*eslint no-useless-escape: "error"*/

"\'";
'\"';
"\#";
"\e";
`\"`;
`\"${foo}\"`;
`\#{foo}`;
/\!/;
/\@/;
/[\[]/;
/[a-z\-]/;

Examples of correct code for this rule:

javascript
/*eslint no-useless-escape: "error"*/

"\"";
'\'';
"\x12";
"\u00a9";
"\371";
"xs\u2111";
`\``;
`\${${foo}}`;
`$\{${foo}}`;
/\\/g;
/\t/g;
/\w\$\*\^\./;
/[[]/;
/[\]]/;
/[a-z-]/;

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-useless-escape
json
{
  "rules": {
    "no-useless-escape": "error"
  }
}

References

Released under the MIT License.