{"record":{"id":"ae2dcd493b317413","repo":"oxc-project/oxc","slug":"invalid-escape-sequence-in-template-literal","errorCode":null,"errorMessage":"Invalid escape sequence in template literal.","messagePattern":"Invalid escape sequence in template literal\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/consistent_template_literal_escape.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn consistent_template_literal_escape_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Invalid escape sequence in template literal.\")\n        .with_help(\"Use '\\\\${' to escape '${' in template literals.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ConsistentTemplateLiteralEscape;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforce consistent style for escaping `${` in template literals.\n    ///\n    /// ### Why is this bad?\n    /// Using `\\${` instead of `${` can improve readability and prevent confusion.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/consistent_template_literal_escape.rs#L1-L27","documentation":"Diagnostic from oxlint's `unicorn/consistent-template-literal-escape` rule. Inside template literals the canonical way to write a literal `${` is `\\${`; writing `$\\{` (escaping the brace instead of the dollar) or `\\$\\{` is inconsistent and flagged as an invalid escape sequence. The scanner walks each template chunk's raw text looking for the `$\\{` sequence, tracking backslash parity so doubled backslashes are handled, and the autofix rewrites the matched range to `\\${`. Tagged templates such as `String.raw` and `html` are skipped because their escapes are meaningful.","triggerScenarios":"Template literals whose raw text contains `$\\{` or `\\$\\{` — e.g. `` const s = `$\\{a}`; `` or `` const s = `\\$\\{a}`; `` — including when interpolations surround the sequence (`${expr}$\\{a}`). Plain string literals and tagged templates are not flagged.","commonSituations":"Code generating template-literal source text, shader/GraphQL snippets, or docs examples where authors escaped the brace reflexively; migration from string concatenation where `$` and `{` were separate; enabling the unicorn style preset.","solutions":["Write the escape as `\\${` — backslash before the dollar, plain `{` after.","Run `oxlint --fix`; it normalizes every variant (`$\\{`, `\\$\\{`) to `\\${` in one pass.","For tagged templates that must keep raw text, ensure they are tagged (e.g. String.raw) so the rule skips them."],"exampleFix":"// before\nconst s = `$\\{a}`;\n// after\nconst s = `\\${a}`;","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write a literal `${` inside template literals as `\\${` — escape the dollar, not the brace.","Never write `$\\{`; it renders the same but the rule (and readers) treat it as inconsistent.","Use tagged templates (e.g. String.raw) when raw backslash sequences must survive verbatim."],"tags":["oxlint","lint","unicorn","template-literals","escaping","style"],"backgroundTag":"template-literal-escaping","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}