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 zero. What it means
Raised by unicorn/explicit-length-check when code checks a non-zero length via a non-explicit comparison while checking for the empty case, e.g. if (arr.length === 0) else-branches should use the explicit non-zero form.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs:34
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)
}
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum NonZero {
/// Enforces non-zero to be checked with `foo.length > 0`.
#[default]
GreaterThan,
/// Enforces non-zero to be checked with `foo.length !== 0`.
NotEqual,
}
View on GitHub (pinned to e1e7af627c)
Solutions
- Use the explicit comparison form suggested in the message, e.g. arr.length !== 0 or arr.length > 0.
- Align the comparison operator with the configured rule mode.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs:34 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/534e44c5ecac555a.
Report an issue: GitHub.