unicorn/no-hex-escape
Require Unicode escapes such as \u001B instead of hexadecimal escapes such as \x1B
fixable
"\x1B" and "\u001B" are the same character written two ways. \x only reaches the first 256 characters, so a project that uses it ends up with both forms, and a search for one misses the other. \u works for every character.
The rule checks strings, template literals, and regular expressions.
--fix rewrites \x1B to \u001B.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/no-hex-escape" = "error" # or "warn"Examples#
example.js4 problems
const notice = "\xA9 2026 Example Inc."Use Unicode escapes instead of hexadecimal escapes.;
const reset = `\x1B[0mUse Unicode escapes instead of hexadecimal escapes.`;
const controlCharacters = /[\x00Use Unicode escapes instead of hexadecimal escapes.-\x1FUse Unicode escapes instead of hexadecimal escapes.]/;example.jsNo problems
const notice = "© 2026 Example Inc.";
const reset = `\u001B[0m`;
const controlCharacters = /[\u0000-\u001F]/;In String.raw and after an escaped backslash, \x is plain text, not an escape:
example.jsNo problems
const source = String.raw`\x1B\[\d+m`;
const help = "Write \\xA9 for the copyright sign";