oxc-project/oxc · warning · OxcDiagnostic
Use uppercase characters for the value of the escape sequenc
Error message
Use uppercase characters for the value of the escape sequence.
What it means
Diagnostic from oxlint's `unicorn/escape-case` rule. It requires uppercase hex digits in escape sequences: `\xXX`, `\uXXXX`, and `\u{X...}` escapes in string literals, plus `\cX` control escapes in regular expression literals. The scanner walks each string's raw text (skipping `String.raw`-tagged templates) and each regex literal; any lowercase a-f in the escape value is flagged, and the autofix uppercases the value in place.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/escape_case.rs:13
use std::str::Chars;
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
AstNode, context::LintContext, rule::Rule, utils::is_string_raw_tagged_template_expression,
};
fn escape_case_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Use uppercase characters for the value of the escape sequence.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct EscapeCase;
declare_oxc_lint!(
/// ### What it does
///
/// Enforces defining escape sequence values with uppercase characters rather than lowercase ones.
/// This promotes readability by making the escaped value more distinguishable from the identifier.
///
/// ### Why is this bad?
///
/// Using lowercase characters in escape sequences makes them less readable and harder to distinguish
/// from surrounding code. Most style guides recommend uppercase for consistency and clarity.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
Solutions
- Uppercase the hex digits: `\xA9`, `\uD834`, `\u{1D306}`, `/\cA/`.
- Run `oxlint --fix` once to normalize every literal in the project.
- Keep `String.raw` templates for text that must preserve raw escapes.
Example fix
// before const foo = "\xa9"; // after const foo = "\xA9";
Defensive patterns
Strategy: validation
Prevention
- Write hex escapes uppercase: `\xA9`, `\uD834`, `\u{1D306}`, `/\cA/`.
- Run `oxlint --fix` once when enabling the rule to normalize all existing literals.
- Keep raw escape sequences in `String.raw` tagged templates, which the rule skips.
When it happens
Trigger: `const foo = "\xa9";`, `"\ud834"`, `"\u{1d306}"`, or the regex `/\ca/` — any escape sequence whose hex digits include lowercase characters in a non-raw string or regex literal.
Common situations: Hand-typed color/unicode escapes in older code; ANSI escape strings (`\x1b` vs `\x1B`); enabling the unicorn pedantic preset and normalizing a legacy codebase.
Related errors
- Use a regular expression literal instead of the `RegExp` con
- Prefer `{} {}` over `{} {}` to check {}.
- Invalid escape sequence in template literal.
- No spaces inside empty pair of braces allowed
- Use Unicode escapes instead of hexadecimal escapes.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/969e4fd3ecaa37dc.
Report an issue: GitHub.