{"record":{"id":"dc14eb2a4ff76b6a","repo":"oxc-project/oxc","slug":"use-unicode-escapes-instead-of-hexadecimal-escapes","errorCode":null,"errorMessage":"Use Unicode escapes instead of hexadecimal escapes.","messagePattern":"Use Unicode escapes instead of hexadecimal escapes\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"info","filePath":"crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs","lineNumber":15,"sourceCode":"use oxc_ast::{AstKind, ast::StringLiteral};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_regular_expression::{\n    ast::{Character, CharacterKind},\n    visit::Visit,\n};\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode, context::LintContext, rule::Rule, utils::is_string_raw_tagged_template_expression,\n};\n\nfn no_hex_escape_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use Unicode escapes instead of hexadecimal escapes.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoHexEscape;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces a convention of using [Unicode escapes](https://mathiasbynens.be/notes/javascript-escapes#unicode)\n    /// instead of [hexadecimal escapes](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) for\n    /// consistency and clarity.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using hexadecimal escapes can be less readable and harder to understand\n    /// when compared to Unicode escapes.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs#L1-L33","documentation":"Diagnostic from the oxlint rule `unicorn/no-hex-escape`. It enforces Unicode escapes (`\\u0041`, `\\u{1B}`) over hexadecimal escapes (`\\x41`) in string literals, template literals, and regular expressions. Both forms produce identical strings, but the `\\u` forms are self-consistent and generalize to all code points, while `\\xNN` only covers Latin-1. `String.raw` tagged templates are exempt because they produce literal backslash sequences, not escapes.","triggerScenarios":"Any `\\xNN` escape in a string literal (`'\\x1B[31m'`), a template literal, or a RegExp character class (`/[\\x00-\\x1f]/`) — except inside String.raw tagged templates.","commonSituations":"Terminal ANSI escape codes, binary protocol literals, regex character classes over control characters; mixed escape styles after merging code from several authors or eras.","solutions":["Convert to Unicode escapes: `\\x1B` becomes `\\u{1B}` or `\\u001B`; `\\x41` becomes `\\u0041`","When you need literal backslash-x text, use String.raw`\\x1B`, which the rule ignores","In regexes, prefer the u flag with `\\u{...}` or Unicode property escapes"],"exampleFix":"// before\nconst ESC = '\\x1B';\n\n// after\nconst ESC = '\\u{1B}';","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use \\u escapes everywhere; \\xNN is Latin-1-only and inconsistent with astral escapes","Use String.raw when literal backslash sequences are needed","Settle on one escape style per file; this rule exists to stop style drift"],"tags":["strings","unicode","regex","style","oxlint"],"backgroundTag":"escape-sequence-style","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"}