Skip to content

unnecessaryEscapes

Reports unnecessary escape sequences in string literals and template strings.

✅ This rule is included in the ts stylistic presets.

Escape sequences in JavaScript strings serve specific purposes like representing special characters (\n, \t) or characters that are difficult to type directly. However, many characters don’t need escaping, and unnecessary escapes reduce code readability without providing any benefit.

const
const message: "ade"
message
= "\a\d\e";
const
const pattern: "[]"
pattern
= "\[\]";
const
const newline: "\n"
newline
= "\n";
const
const tab: "\t"
tab
= "\t";
const
const unicode: "©"
unicode
= "\u00A9";
const
const hex: "©"
hex
= "\xA9";
const
const backslash: "\\"
backslash
= "\\";
const
const template: "prefix @ suffix"
template
= `prefix \@ suffix`;

This rule is not configurable.

If you have legacy code with many unnecessary escapes and refactoring would be too costly, you may disable this rule. However, the rule provides automatic fixes that make cleanup straightforward.

Made with ❤️‍🔥 around the world by the Flint team and contributors.