oxc-project/oxc · warning · OxcDiagnostic
Use the 'u' flag.
Error message
Use the 'u' flag.
What it means
oxlint `eslint/require-unicode-regexp` (default configuration): a regex was created without the `u` flag. The else-branch of `require_unicode_regexp_diagnostic` (require_unicode_regexp.rs:33) selects 'Use the \'u\' flag.' / 'Add the \'u\' flag.'. Unicode mode makes `.` and quantifiers operate on code points rather than UTF-16 code units and enables `\p{...}` properties, preventing subtle surrogate-pair bugs.
Source
Thrown at crates/oxc_linter/src/rules/eslint/require_unicode_regexp.rs:33
AstNode,
ast_util::get_declaration_of_variable,
ast_util::variable_declaration_kind,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
utils::is_regexp_callee,
};
fn require_unicode_regexp_diagnostic(
span: Span,
require_flag: Option<&RequireFlag>,
) -> OxcDiagnostic {
let (msg, help_msg) = if matches!(require_flag, Some(RequireFlag::V)) {
("Use the 'v' flag.", "Add the 'v' flag.")
} else {
("Use the 'u' flag.", "Add the 'u' flag.")
};
OxcDiagnostic::warn(msg)
.with_note("The 'u' and 'v' flags enable Unicode-aware regular expression behavior and stricter pattern parsing.")
.with_help(help_msg)
.with_label(span)
}
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct RequireUnicodeRegexpConfig {
/// The `u` flag may be preferred in environments that do not support the `v` flag.
///
/// Examples of **incorrect** code for this rule with the `{ "requireFlag": "u" }` option:
/// ```js
/// const fooEmpty = /foo/;
/// const fooEmptyRegexp = new RegExp('foo');
/// const foo = /foo/v;
/// const fooRegexp = new RegExp('foo', 'v');
/// ```
///View on GitHub (pinned to e1e7af627c)
Solutions
- Add `u` to the literal: `/foo/` becomes `/foo/u`.
- Add `u` to constructor flags: `new RegExp("foo", "iu")`.
- After adding `u`, re-test: some patterns (unnecessary escapes, `.`-based splits) become errors or behave differently under Unicode mode.
- For specific unavoidable cases, disable per line with `// oxlint-disable-next-line require-unicode-regexp`.
Example fix
// before const emoji = /^.+$/.test(text); // after const emoji = /^.+$/u.test(text);
Defensive patterns
Strategy: validation
Validate before calling
# regex literals without u or v rg -n --pcre2 '/(?!/)[^\n\\r]*/[dgimsy]*['"'"'",; )]' src/
Prevention
- Habitually append `/u` to regexes that touch user text, emoji, or non-ASCII identifiers.
- After adding `u`, re-run tests — escape rules and `.` semantics change (code points, not code units).
- Enable require-unicode-regexp in shared configs so new regexes are consistent.
When it happens
Trigger: `/foo/`, `/\d+/`, `new RegExp("foo")`, or `new RegExp("foo", "i")` — any regex whose flags string does not include `u` (or `v`).
Common situations: Enabling this rule on a legacy codebase with many pre-`u` regexes; emoji/CJK text handling where surrogate-pair bugs matter; porting tests from another project's config.
Related errors
- Use the 'v' flag.
- Backreference '{back_reference}' will be ignored. It referen
- Backreference '{back_reference}' will be ignored. It referen
- Backreference '{back_reference}' will be ignored. It referen
- Unnecessary escape character {escape_char:?}
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/3e1decc14c606aaf.
Report an issue: GitHub.