oxc-project/oxc · warning · OxcDiagnostic
Unexpected combining class in character class.
Error message
Unexpected combining class in character class.
What it means
Diagnostic from oxlint's eslint/no-misleading-character-class rule (crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs:42). It reports a combining character (combining diacritical mark, e.g. U+0300) inside a regex character class. A class like /[à]/ where the à is stored decomposed (a + U+0300) does not match the accented character — it matches either 'a' or the bare combining mark — so the author's intent is broken. The help says to use the NFC-normalized single code point or explicit \u{...} escapes.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_misleading_character_class.rs:42
RegexFlagsParseResult, get_regex_flags_span, get_regex_pattern_span, is_regexp_callee,
run_on_regex_node,
},
};
fn surrogate_pair_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected surrogate pair in character class.")
.with_help("Use Unicode code point escapes (e.g., \\u{1F44D}) instead of surrogate pairs.")
.with_label(span)
}
fn surrogate_pair_without_flag_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected surrogate pair in character class.")
.with_help("Add the Unicode flag 'u'.")
.with_label(span)
}
fn combining_class_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected combining class in character class.")
.with_help("Replace the character with its normalized form (NFC) or use Unicode code point escapes instead of combining sequences.")
.with_label(span)
}
fn emoji_modifiers_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected emoji modifier in character class.")
.with_help("Use Unicode code point escapes (e.g., \\u{1F3FB} for the light skin tone modifier) instead of emoji modifier sequences in character classes.")
.with_label(span)
}
fn regional_indicator_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected regional indicator in character class.")
.with_help("Use Unicode code point escapes (e.g., \\u{1F1EF} for the regional indicator symbol for 'J') instead of regional indicator symbol pairs in character classes.")
.with_label(span)
}
fn zwj_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected joined character sequence in character class.")View on GitHub (pinned to e1e7af627c)
Solutions
- Use the precomposed character from NFC normalization: /[à]/ where à is the single code point U+00E0
- Or write explicit code point escapes: /[\u{00E0}]/u
- Normalize input with String.prototype.normalize('NFC') before matching so decomposed data cannot slip through
Example fix
// before (à stored as a + U+0300)
const accented = /[à]/; // matches 'a' or the bare mark, not à
// after (single NFC code point)
const accented = /[\u{00E0}]/u; // matches à (U+00E0) Defensive patterns
Strategy: validation
Validate before calling
// Reject combining marks in character classes; require precomposed/NFC forms
import { readFileSync } from 'node:fs';
const COMBINING = /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/;
const src = readFileSync(process.argv[2], 'utf8');
if (COMBINING.test(src)) {
console.error('combining mark in source; normalize to NFC or use \\u{...} escapes');
process.exitCode = 1;
} Type guard
const isNFC = (s) => s === s.normalize('NFC'); Prevention
- Normalize all user input with .normalize('NFC') before regex matching
- Write accented characters in character classes as \u{...} code point escapes to avoid encoding surprises
- Be careful pasting from macOS file names and NFD-heavy sources; lint the file afterward
When it happens
Trigger: Character classes containing decomposed accented letters typed or pasted in NFD form: /[a\u0300]/ (same as decomposed à); /[é]/ where the source file stores e + U+0301; equivalent classes built via new RegExp from user-provided strings.
Common situations: Copy-pasting accented characters from macOS file names (which use NFD) into a regex; sanitizing French/German/Spanish input with an allow-list character class; text normalization pipelines mixing NFC and NFD data.
Related errors
- Invalid regular expression: `u` and `v` flags should be used
- Unexpected surrogate pair in character class.
- A regular expression literal can be confused with '/='.
- Empty character class will not match anything
- Invalid regular expression: Duplicated flag
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/3be6d93c890d1a5e.
Report an issue: GitHub.