For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/no-accidental-bitwise-operator.md.
close

no-accidental-bitwise-operator

Unreleased

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-accidental-bitwise-operator': 'error',
    },
  },
]);

Rule Details

Disallow bitwise operators where a logical operator was likely intended. The rule reports & when an identifier is followed by a property access on the same identifier, such as object & object.property. It also reports | and |= when the right operand is a string, template literal, boolean, array, object, class, or function expression used as an apparent fallback.

Incorrect

if (object & object.property) {
  use(object.property);
}

options = options | {};
input |= '';

Correct

if (object && object.property) {
  use(object.property);
}

options = options || {};
input ||= '';

const masked = flags & MASK;
const truncated = value | 0;

Suggestions

Editor suggestions replace the operator with &&, ||, or ||= and add parentheses when needed to preserve how the surrounding operators group. Review each suggestion before applying it because logical operators short-circuit and can change runtime behavior.

Options

This rule has no options.

Original Documentation