oxc-project/oxc · warning · OxcDiagnostic
Use the 'v' flag.
Error message
Use the 'v' flag.
What it means
oxlint `eslint/require-unicode-regexp` with `{ "requireFlag": "v" }`: a regex literal or `RegExp` construction lacks the `v` flag. In `require_unicode_regexp_diagnostic` (require_unicode_regexp.rs:33) the V branch selects message 'Use the \'v\' flag.' and help 'Add the \'v\' flag.'. The `v` flag enables Unicode Sets mode (`\p{...}` classes, `--` subtraction) and stricter parsing; the config comment notes `u` may be preferred where `v` is unsupported.
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 the flag to the literal: `/foo/` becomes `/foo/v` (note: `v` implies `u`, so `/foo/u` becomes `/foo/v`).
- For constructed regexes pass the flag: `new RegExp("foo", "v")`.
- If you must support runtimes without `v`, set `"requireFlag": "u"` in the rule config instead.
Example fix
// before
const re = /^\p{Letter}+$/u;
// after
const re = /^\p{Letter}+$/v; Defensive patterns
Strategy: validation
Validate before calling
# regex literals missing the v flag rg -n --pcre2 '/[^\n]*/[dgimsuy]*' src/ | rg -v '/[^\n]*/[a-z]*v[a-z]*'
Prevention
- End every regex literal with `/v` when the config mandates it; `v` supersedes `u`.
- Check runtime support (Node 20+, modern browsers) before standardizing on `v`.
- If a target env lacks `v`, configure `"requireFlag": "u"` instead of scattering disables.
When it happens
Trigger: Rule configured with `requireFlag: "v"` and code containing `/foo/`, `/\d+/u`, or `new RegExp("foo")` — any regex without `v` in its flags.
Common situations: Shared config that mandates v-mode for consistent Unicode handling; upgrading a config from `u` to `v` and re-linting an older codebase; targeting Node/browsers that gained `v` support only recently.
Related errors
- Use the 'u' 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/2b4b19629807e652.
Report an issue: GitHub.