oxc-project/oxc · error · OxcDiagnostic

Unexpected negated condition.

Error message

Unexpected negated condition.

What it means

Raised by no-negated-condition (eslint/unicorn shared) when an if/else or conditional expression tests a negated condition with both branches present. Inverting the condition makes the happy path more readable.

Source

Thrown at crates/oxc_linter/src/rules/shared/eslint_unicorn/no_negated_condition.rs:21

    ast::{ConditionalExpression, Expression, IfStatement, Statement},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, Span};
use oxc_syntax::{
    identifier::is_identifier_part,
    line_terminator::is_line_terminator,
    operator::{BinaryOperator, UnaryOperator},
};

use crate::{
    AstNode,
    ast_util::could_be_asi_hazard,
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
};

fn no_negated_condition_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected negated condition.")
        .with_help("Remove the negation operator and switch the consequent and alternate branches.")
        .with_label(span)
}

pub const DOCUMENTATION: &str = r"### What it does

Disallow negated conditions.

### Why is this bad?

Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition.

### Examples

Examples of **incorrect** code for this rule:
```javascript
if (!a) {
	doSomethingC();

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the negation operator and swap the if/else branches.
  2. If there is no else branch, keep the negation (the rule only fires when both branches exist).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/shared/eslint_unicorn/no_negated_condition.rs:21 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/b19458680811aa11. Report an issue: GitHub.