close

no-negation-in-equality-check

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-negation-in-equality-check': 'error',
    },
  },
]);

Rule Details

Report a single logical negation on the left side of ===, !==, ==, or !=. Such an expression compares the negated boolean value, rather than negating the result of the comparison.

Examples of incorrect code:

if (!value === expected) {}
if (!value != expected) {}

Examples of correct code:

if (value !== expected) {}
if (!(value === expected)) {}

Double negation and negation on the right side are not reported. Other binary operators are outside this rule's scope.

Suggestions

The rule suggests removing the left-side ! and inverting the comparison operator. This is an editor suggestion, not an automatic fix: the two expressions can have different behavior, so the intended comparison must be chosen explicitly.

Suggestions preserve surrounding comments and keyword spacing. They also add parentheses or a leading semicolon when removing ! would otherwise change a return, throw, or statement boundary.

Options

This rule has no options.

Original Documentation