oxc-project/oxc · warning · OxcDiagnostic
Both sides of the logical operator are the same
Error message
Both sides of the logical operator are the same
What it means
Reported by `oxc/const-comparisons` when both operands of an `&&`/`||` expression are structurally the same expression (`is_same_expression`), e.g. `x && x`. The logical expression always evaluates to the same value as the operand itself, so the second evaluation is pure redundancy (and a duplicate side effect if the operand were a call). This check runs before the equivalent and complementary variants.
Source
Thrown at crates/oxc_linter/src/rules/oxc/const_comparisons.rs:55
])
}
fn constant_comparison_diagnostic(
span: Span,
evaluates_to: bool,
help: String,
precedence_note: Option<String>,
) -> OxcDiagnostic {
let diagnostic =
OxcDiagnostic::warn(format!("This comparison will always evaluate to {evaluates_to}"))
.with_help(help)
.with_label(span);
if let Some(note) = precedence_note { diagnostic.with_note(note) } else { diagnostic }
}
fn identical_expressions_logical_operator(left_span: Span, right_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Both sides of the logical operator are the same")
.with_help("This logical expression will always evaluate to the same value as the expression itself.")
.with_labels([
left_span.label("If this expression evaluates to true"),
right_span
.label("This expression will always evaluate to true"),
])
}
fn equivalent_expressions_logical_operator(left_span: Span, right_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Both sides of the logical operator are equivalent")
.with_help("This logical expression will always evaluate to the same value as either side.")
.with_labels([
left_span.label("If this expression evaluates to true"),
right_span.label("This equivalent expression will always evaluate to true"),
])
}
fn complementary_expressions_logical_operator(View on GitHub (pinned to e1e7af627c)
Solutions
- Keep one operand: `cond`
- If a second, different condition was intended, restore it
- Run oxlint so duplicated logical operands are flagged automatically
Example fix
// before
if (isValid && isValid) { /* ... */ }
// after
if (isValid) { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — correctness rule (on in the default category set)
{
"rules": { "oxc/const-comparisons": "error" }
}
// CLI: npx oxlint src/ Prevention
- After merging conditions or resolving merge conflicts, scan the chain for duplicate terms
- Keep boolean chains short; extract named predicates for readability
- Run oxlint in CI to catch duplicated logical operands
When it happens
Trigger: `cond && cond`, `isValid || isValid`; duplicated conditions inside a long boolean chain.
Common situations: Merging two conditions and forgetting to delete one; merge-conflict resolution leaving both copies; long `if` chains where a duplicated term goes unnoticed.
Related errors
- Left-hand side of `&&` operator has no effect.
- Right-hand side of `&&` operator has no effect.
- Unexpected constant comparison
- Both sides of the logical operator are equivalent
- Global flag (g) is missing in the regular expression supplie
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/ef6900d541477302.
Report an issue: GitHub.