oxc-project/oxc · warning · OxcDiagnostic

Expected {expected} and instead saw {actual}

Error message

Expected {expected} and instead saw {actual}

What it means

Oxlint's port of the ESLint rule eqeqeq: equality comparisons must use `===`/`!==` unless an option carves out an exception. The message interpolates both operators ("Expected '===' and instead saw '=='") and the help suggests the strict operator. The rule config is a tuple — Eqeqeq(CompareType, EqeqeqOptions) at crates/oxc_linter/src/rules/eslint/eqeqeq.rs:17 — where CompareType selects `always` (default) or `smart`, and the options object has a `null` field controlling comparisons against null. The rule imports RuleFixer, so `--fix` rewrites the operator automatically.

Source

Thrown at crates/oxc_linter/src/rules/eslint/eqeqeq.rs:20

    AstKind,
    ast::{BinaryExpression, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
use schemars::JsonSchema;
use serde::Deserialize;

use crate::{
    AstNode,
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
    rule::{Rule, TupleRuleConfig},
};

fn eqeqeq_diagnostic(actual: &str, expected: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Expected {expected} and instead saw {actual}"))
        .with_help(format!("Prefer {expected} operator"))
        .with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub struct Eqeqeq(CompareType, EqeqeqOptions);

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct EqeqeqOptions {
    /// Configuration for whether to allow/disallow comparisons against `null`,
    /// e.g. `foo == null` or `foo != null`
    null: NullType,
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "kebab-case")]

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Change `==` to `===` (and `!=` to `!==`) — the strict form is almost always the intended semantics.
  2. For null-and-undefined checks write `x === null || x === undefined`, or run with `smart` so `x == null` stays allowed.
  3. Run oxlint with `--fix` to auto-rewrite the operators.
  4. Normalize operand types first (e.g. Number(value)) so strict equality compares like with like.

Example fix

// before
if (value == null) {
  return;
}

// after
if (value === null || value === undefined) {
  return;
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — allow the idiomatic null check while forcing === elsewhere
{
  "rules": {
    "eqeqeq": ["warn", "smart"]
  }
}

Prevention

When it happens

Trigger: Any `==`/`!=` comparison under `always`; under `smart`, null comparisons and some literal-to-literal checks are permitted; a stricter `null` setting reports even `x == null`.

Common situations: Checking null-or-undefined with `x == null`; comparing user input against '' or 0 where coercion was assumed; migrating an ESLint config that relied on the deprecated "allow-null" value.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/0023ce5bc22ad24c. Report an issue: GitHub.