1.2 KiB
Don't remove useless \ in string literals (#16563 by @sosukesuzuki)
Previously, Prettier would remove useless escape characters (\) from string literals. However, this behavior was inconsistent as it did not apply to template literals, which was reported in issue #16542.
This issue is a feature request to extend this behavior to template literals as well.
After discussing this internally, the Prettier team concluded that removing useless escape characters, whether in string literals or template literals, is the responsibility of a linter, not a formatter.
This change disables the removal of useless escape characters in string literals across all languages supported by Prettier. To keep the previous behavior, we recommend using ESLint rules like no-useless-escape.
Escaping quotes within string literals (e.g. "\"\'") works the same as before. This is explained on the Rationale page of the official documentation.
// Input
const str = "\a";
// Prettier stable
const str = "a";
// Prettier main
const str = "\a";