{"record":{"id":"3e1decc14c606aaf","repo":"oxc-project/oxc","slug":"use-the-u-flag","errorCode":null,"errorMessage":"Use the 'u' flag.","messagePattern":"Use the 'u' flag\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/require_unicode_regexp.rs","lineNumber":33,"sourceCode":"    AstNode,\n    ast_util::get_declaration_of_variable,\n    ast_util::variable_declaration_kind,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_regexp_callee,\n};\n\nfn require_unicode_regexp_diagnostic(\n    span: Span,\n    require_flag: Option<&RequireFlag>,\n) -> OxcDiagnostic {\n    let (msg, help_msg) = if matches!(require_flag, Some(RequireFlag::V)) {\n        (\"Use the 'v' flag.\", \"Add the 'v' flag.\")\n    } else {\n        (\"Use the 'u' flag.\", \"Add the 'u' flag.\")\n    };\n\n    OxcDiagnostic::warn(msg)\n        .with_note(\"The 'u' and 'v' flags enable Unicode-aware regular expression behavior and stricter pattern parsing.\")\n        .with_help(help_msg)\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\nstruct RequireUnicodeRegexpConfig {\n    /// The `u` flag may be preferred in environments that do not support the `v` flag.\n    ///\n    /// Examples of **incorrect** code for this rule with the `{ \"requireFlag\": \"u\" }` option:\n    /// ```js\n    /// const fooEmpty = /foo/;\n    /// const fooEmptyRegexp = new RegExp('foo');\n    /// const foo = /foo/v;\n    /// const fooRegexp = new RegExp('foo', 'v');\n    /// ```\n    ///","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/require_unicode_regexp.rs#L15-L51","documentation":"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.","triggerScenarios":"`/foo/`, `/\\d+/`, `new RegExp(\"foo\")`, or `new RegExp(\"foo\", \"i\")` — any regex whose flags string does not include `u` (or `v`).","commonSituations":"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.","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`."],"exampleFix":"// before\nconst emoji = /^.+$/.test(text);\n\n// after\nconst emoji = /^.+$/u.test(text);","handlingStrategy":"validation","validationCode":"# regex literals without u or v\nrg -n --pcre2 '/(?!/)[^\\n\\\\r]*/[dgimsy]*['\"'\"'\",; )]' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["eslint","oxlint","regex","unicode","lint"],"backgroundTag":"require-unicode-regexp","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}