oxc-project/oxc · error · OxcDiagnostic

Use `.{prop_name} {op_and_rhs}` when checking {prop_name} is

Error message

Use `.{prop_name} {op_and_rhs}` when checking {prop_name} is not zero.

What it means

Raised by unicorn/explicit-length-check when code tests truthiness of a length property (if (arr.length)) instead of explicitly comparing against zero. Truthiness checks are less clear and can hide intent.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs:23

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::{BinaryOperator, LogicalOperator};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{
    AstNode,
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    utils::{
        expression_uses_optional_chain, get_boolean_ancestor, is_boolean_call, is_boolean_node,
        pad_fix_with_token_boundary,
    },
};

fn non_zero(span: Span, prop_name: &str, op_and_rhs: &str, help: Option<String>) -> OxcDiagnostic {
    let mut d = OxcDiagnostic::warn(format!(
        "Use `.{prop_name} {op_and_rhs}` when checking {prop_name} is not zero."
    ))
    .with_label(span);
    if let Some(x) = help {
        d = d.with_help(x);
    }
    d
}

fn zero(span: Span, prop_name: &str, op_and_rhs: &str, help: Option<String>) -> OxcDiagnostic {
    let mut d = OxcDiagnostic::warn(format!(
        "Use `.{prop_name} {op_and_rhs}` when checking {prop_name} is zero."
    ));
    if let Some(x) = help {
        d = d.with_help(x);
    }
    d.with_label(span)
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Write the explicit comparison: if (arr.length > 0) (or the operator form suggested by the diagnostic).
  2. Configure the rule's mode (greater-than, not-equal, equal) to the project convention.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs:23 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/8fbdc3ff7d7bcbf2. Report an issue: GitHub.