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 message = "\a\d\e";
const pattern = "\[\]";
const newline = "\n";
const tab = "\t";
const unicode = "\u00A9";
const hex = "\xA9";
const backslash = "\\";
const 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.