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.
Examples
Section titled “Examples”Unnecessary Letter Escapes
Section titled “Unnecessary Letter Escapes”const message = "\a\d\e";const message = "ade";Unnecessary Symbol Escapes
Section titled “Unnecessary Symbol Escapes”const pattern = "\[\]";const pattern = "[]";Valid Escape Sequences
Section titled “Valid Escape Sequences”const newline = "\n";const tab = "\t";const unicode = "\u00A9";const hex = "\xA9";const backslash = "\\";Template Literals
Section titled “Template Literals”const template = `prefix \@ suffix`;const template = `prefix @ suffix`;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 around the world by
the Flint team and contributors.