{"record":{"id":"6ae5da9c45e282b0","repo":"oxc-project/oxc","slug":"unexpected-use-of-operator","errorCode":null,"errorMessage":"Unexpected use of `{operator:?}`.","messagePattern":"Unexpected use of `(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_bitwise.rs","lineNumber":18,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\nuse oxc_syntax::operator::BinaryOperator;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_bitwise_diagnostic(operator: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected use of `{operator:?}`.\"))\n        .with_help(\"bitwise operators are not allowed, maybe you mistyped `&&` or `||`?\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoBitwise(Box<NoBitwiseConfig>);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoBitwiseConfig {\n    /// The `allow` option permits the given list of bitwise operators to be used\n    /// as exceptions to this rule.\n    ///\n    /// For example `{ \"allow\": [\"~\"] }` would allow the use of the bitwise operator\n    /// `~` without restriction. Such as in the following:\n    ///\n    /// ```javascript\n    /// ~[1,2,3].indexOf(1) === -1;","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_bitwise.rs#L1-L36","documentation":"Diagnostic from the oxlint rule `no-bitwise` (crates/oxc_linter/src/rules/eslint/no_bitwise.rs). It fires on use of bitwise operators (`&`, `|`, `^`, `~`, `<<`, `>>`, `>>>`) and bitwise-assignment forms. The rule assumes bitwise operators in typical application code are typos for logical operators (`&&`, `||`); the message renders the operator with Rust `{:?}` formatting, so it appears quoted, e.g. Unexpected use of `\"&\"`. The config supports an `allow` list of operator exceptions.","triggerScenarios":"Any BinaryExpression with a bitwise operator, UnaryExpression with `~`, or an assignment expression with a bitwise compound operator that is not in the configured `allow` array — e.g. `if (a & b)`, `flags |= MASK`, `x = ~y`.","commonSituations":"Teams that adopted the eslint `no-bitwise` restriction migrating configs to oxlint; accidental `&`/`|` in place of `&&`/`||` in conditions; legacy flag-manipulation code (permission masks, color channel math) passing through a config without an `allow` entry.","solutions":["If the operator is a typo, replace it with the logical operator: `a && b`, `a || b`.","If the bitwise use is intentional (masks, hashing, binary protocols), allow it via config: `{ \"rules\": { \"no-bitwise\": [\"error\", { \"allow\": [\"&\", \"|\", \"^\", \"<<\", \">>\", \">>>\"] }] } }` in .oxlintrc.json.","For isolated intentional uses, suppress inline with `// oxlint-disable-next-line no-bitwise`.","Where truly needed for performance, extract flag logic into a named helper module and allow the rule only in that directory."],"exampleFix":"// before\nif (mode & 2) { /* ... */ }\n\n// after (typo case)\nif (mode && hasFlag(mode, 2)) { /* ... */ }\n\n// after (intentional case: .oxlintrc.json)\n// { \"rules\": { \"no-bitwise\": [\"error\", { \"allow\": [\"&\"] }] } }","handlingStrategy":"fallback","validationCode":"// Audit which bitwise operators your codebase actually uses before enabling the rule\nconst used = execSync(\"rg -o '[&|^~]|<<|>>>?|>>' src/ | sort | uniq -c\").toString();\n// then configure .oxlintrc.json allow list from this inventory","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Port your ESLint `no-bitwise` allow list verbatim to .oxlintrc.json when adopting oxlint.","Keep flag/mask logic in dedicated modules and scope the allow list there via overrides.","Prefer named flag helpers (hasFlag/setFlag) over inline bitwise arithmetic in app code."],"tags":["lint","bitwise","stylistic","config","oxlint"],"backgroundTag":"bitwise-operator-misuse","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}