{"record":{"id":"98519d4333d071b2","repo":"oxc-project/oxc","slug":"this-comparison-will-always-evaluate-to-evaluates","errorCode":null,"errorMessage":"This comparison will always evaluate to {evaluates_to}","messagePattern":"This comparison will always evaluate to (.+?)","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/oxc/const_comparisons.rs","lineNumber":47,"sourceCode":"            right_span.label(\"This will always evaluate to true.\"),\n        ])\n}\n\nfn impossible(span: Span, span1: Span, x2: &str, x3: &str, x4: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected constant comparison\").with_help(x4.to_string()).with_labels([\n        span.label(format!(\"Requires that {x2}\")),\n        span1.label(format!(\"Requires that {x3}\")),\n    ])\n}\n\nfn constant_comparison_diagnostic(\n    span: Span,\n    evaluates_to: bool,\n    help: String,\n    precedence_note: Option<String>,\n) -> OxcDiagnostic {\n    let diagnostic =\n        OxcDiagnostic::warn(format!(\"This comparison will always evaluate to {evaluates_to}\"))\n            .with_help(help)\n            .with_label(span);\n\n    if let Some(note) = precedence_note { diagnostic.with_note(note) } else { diagnostic }\n}\n\nfn identical_expressions_logical_operator(left_span: Span, right_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Both sides of the logical operator are the same\")\n                    .with_help(\"This logical expression will always evaluate to the same value as the expression itself.\")\n                    .with_labels([\n                        left_span.label(\"If this expression evaluates to true\"),\n                        right_span\n                            .label(\"This expression will always evaluate to true\"),\n                    ])\n}\n\nfn equivalent_expressions_logical_operator(left_span: Span, right_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Both sides of the logical operator are equivalent\")","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs#L29-L65","documentation":"Fired by `oxc/const-comparisons` when a relational expression (`<`, `<=`, `>`, `>=`) compares an expression with itself: `a < a` is always false and `a >= a` is always true. The message interpolates the constant result; the help explains 'Because `a` will never be less than itself'. When such a self-comparison appears unparenthesized as the right side of `||` or `??`, an extra note explains the precedence trap (comparisons bind tighter than logical operators) and shows the parenthesized form.","triggerScenarios":"`if (a < a) {}`; `while (x.id >= x.id) {}`; precedence case `a || b >= b`, which parses as `a || (b >= b)` when `(a || b) >= c` was meant.","commonSituations":"Copy-paste where the second operand was never changed; mixing `||`/`??` with comparisons without parentheses; auto-generated comparison code from templates.","solutions":["Compare against the intended other operand: `a < b`","For the precedence case, add parentheses so the logical result is compared: `(a || b) >= c`","Remove the tautological comparison if it was purely accidental"],"exampleFix":"// before\nif (a < a) { /* never true */ }\n\n// after\nif (a < b) { /* ... */ }","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — correctness rule (on in the default category set)\n{\n  \"rules\": { \"oxc/const-comparisons\": \"error\" }\n}\n// CLI: npx oxlint src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Review any comparison whose operands came from copy-paste","Parenthesize whenever a comparison sits next to `||` or `??`: `(a || b) >= c`","Run oxlint so self-comparisons and precedence traps are reported"],"tags":["oxlint","oxc","comparison","logic-bug","javascript","operator-precedence"],"backgroundTag":"self-comparison","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}