{"record":{"id":"3f7c37a124a06ec3","repo":"oxc-project/oxc","slug":"a-regular-expression-literal-can-be-confused-with","errorCode":null,"errorMessage":"A regular expression literal can be confused with '/='.","messagePattern":"A regular expression literal can be confused with '/='\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_div_regex.rs","lineNumber":10,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_regular_expression::ast::{CharacterKind, Term};\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_div_regex_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"A regular expression literal can be confused with '/='.\")\n        .with_help(\"Rewrite `/=` into `/[=]`\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoDivRegex;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow equal signs explicitly at the beginning of regular expressions.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Characters /= at the beginning of a regular expression literal can be confused with a\n    /// division assignment operator.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_div_regex.rs#L1-L28","documentation":"This diagnostic comes from the `no_div_regex` rule in oxlint. It reports a regular expression literal whose pattern starts with the character `=`. Such a literal, for example `/=/`, reads like the division-assignment operator `/=`. The rule walks the parsed regex AST and checks the first `Term` of the pattern for an `=` character.","triggerScenarios":"A regex literal whose first character is an equal sign: `var re = /=/;` or `if (/=/.test(token)) { ... }`. The rule inspects the first term of the pattern and its character kind.","commonSituations":"A developer writes a quick test for the assignment operator character, for example in a tokenizer, a parser, or a lint tool. Humans and simple text tooling read `x /= y` where a regex was meant.","solutions":["Rewrite the literal with a character class: `/[=]/`.","Use the RegExp constructor when a class is not wanted: `new RegExp('=')`.","Suppress with `// oxlint-disable-next-line no-div-regex` when the context makes the literal clear."],"exampleFix":"// before\nif (/=/.test(token)) { /* assignment operator */ }\n\n// after\nif (/[=]/.test(token)) { /* assignment operator */ }","handlingStrategy":"validation","validationCode":"// crude scan for regex literals starting with '='\nif (/(^|[^\\\\])\\/=(?!\\/)/.test(src)) console.warn('possible /=/ regex literal; rewrite as /[=]/');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Start regex literals with a character class when the first character is punctuation.","Keep oxlint running in the editor so the report appears while you type the literal."],"tags":["javascript","eslint","lint","regex"],"backgroundTag":"lint-regex-literal","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"}