# bad-bitwise-operator

Rule `oxc/bad-bitwise-operator`. This rule applies when bitwise operators are used where logical operators are expected.

- Source: oxc
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 2.1M weekly downloads of presets that enable it
- Trend: +151.7% last quarter
- Rank: #1517 by reach, #21 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| Oxlint | `oxc/bad-bitwise-operator` | no | safe | plugin `oxc`, category restriction | [docs](https://oxc.rs/docs/guide/usage/linter/rules/oxc/bad-bitwise-operator.html) |
| Biome | `nursery/noAccidentalBitwiseOperators` | yes | unsafe | group nursery, since 2.6.0 | [docs](https://biomejs.dev/linter/rules/no-accidental-bitwise-operators/) |

## Code examples

### Incorrect: the rule reports this

```js
e && e.x
e || {}
e || ''
```

```js
if (obj & obj.prop) {
 console.log(obj.prop);
}
options = options | {};
input |= '';
```

### Correct: the rule accepts this

```js
if (obj && obj.prop) {
 console.log(obj.prop);
}
options = options || {};
input ||= '';
```

Examples from the Oxlint documentation.

## Enable it

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "oxc/bad-bitwise-operator": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noAccidentalBitwiseOperators": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |

## Related rules

- [oxc/branches-sharing-code](https://lintradar.dev/rules/oxc/branches-sharing-code.md): Checks if the `if` and `else` blocks contain shared code that can be moved out of the blocks.
- [oxc/approx-constant](https://lintradar.dev/rules/oxc/approx-constant.md): Disallows the use of approximate constants, instead preferring the use of the constants in the `Math` object.
- [oxc/misrefactored-assign-op](https://lintradar.dev/rules/oxc/misrefactored-assign-op.md): Https://rust-lang.github.io/rust-clippy/master/#/misrefactored_assign_op
- [oxc/no-accumulating-spread](https://lintradar.dev/rules/oxc/no-accumulating-spread.md): Prevents using object or array spreads on accumulators in `Array.prototype.reduce()` and in loops.
- [oxc/no-async-endpoint-handlers](https://lintradar.dev/rules/oxc/no-async-endpoint-handlers.md): Disallows the use of `async` functions as Express endpoint handlers.
- [oxc/no-barrel-file](https://lintradar.dev/rules/oxc/no-barrel-file.md): Disallow the use of barrel files where the file contains `export *` statements, and the total number of modules exceeds a threshold.

---

Web page: https://lintradar.dev/rules/oxc/bad-bitwise-operator. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
