oxc-project/oxc · error · OxcDiagnostic
Negated expression is not allowed in equality check.
Error message
Negated expression is not allowed in equality check.
What it means
Raised by unicorn/no-negation-in-equality-check when one operand of an equality/inequality comparison (==, !=, ===, !==) is a negation (`!x`). The helper receives the current and suggested operators to build advice (e.g. swap === for !==); the faulting input is the negated operand comparison at the labeled span.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/no_negation_in_equality_check.rs:15
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::identifier::is_identifier_start;
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
use crate::{AstNode, ast_util, context::LintContext, rule::Rule};
fn no_negation_in_equality_check_diagnostic(
span: Span,
current_operator: BinaryOperator,
suggested_operator: BinaryOperator,
) -> OxcDiagnostic {
OxcDiagnostic::warn("Negated expression is not allowed in equality check.")
.with_help(format!(
"Remove the negation operator and use '{}' instead of '{}'.",
suggested_operator.as_str(),
current_operator.as_str()
))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoNegationInEqualityCheck;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow negated expressions on the left of (in)equality checks.
///
/// ### Why is this bad?
///View on GitHub (pinned to e1e7af627c)
Solutions
- Drop the negation and use the opposite operator: `!a === b` → `a !== b`
- Move the negation outside the whole comparison if it applies to the result: `!(a === b)`
- Restructure the boolean expression so no operand is negated
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_negation_in_equality_check.rs:15 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/e7db54198166849c.
Report an issue: GitHub.