{"record":{"id":"0882f5904213b716","repo":"oxc-project/oxc","slug":"unexpected-constant-comparison","errorCode":null,"errorMessage":"Unexpected constant comparison","messagePattern":"Unexpected constant comparison","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/oxc/const_comparisons.rs","lineNumber":34,"sourceCode":"    OxcDiagnostic::warn(\"Left-hand side of `&&` operator has no effect.\")\n        .with_help(help)\n        .with_labels([\n            right_span.label(\"If this evaluates to `true`\"),\n            left_span.label(\"This will always evaluate to true.\"),\n        ])\n}\n\nfn redundant_right_hand_side(right_span: Span, left_span: Span, help: String) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Right-hand side of `&&` operator has no effect.\")\n        .with_help(help)\n        .with_labels([\n            left_span.label(\"If this evaluates to `true`\"),\n            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}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs#L16-L52","documentation":"The 'impossible' arm of `oxc/const-comparisons`: an `&&` chain compares one variable in opposite directions against two constants that cannot be satisfied together, e.g. `status_code <= 400 && status_code > 500`. Labels read 'Requires that ...' per comparison and the note derives that the expression is false for every value of the variable — a contradiction, hence 'Unexpected constant comparison'.","triggerScenarios":"`status_code <= 400 && status_code > 500`; `x > 10 && x < 5`; any `<`/`<=` bound whose constant is below the paired `>`/`>=` bound for the same variable inside an `&&`.","commonSituations":"Editing range bounds (e.g. flipping a 4xx check to `<= 400` and `> 500`); mixing up inclusive/exclusive endpoints; converting `||` chains to `&&` without inverting the comparisons.","solutions":["Rewrite the range with ordered bounds: `status_code >= 400 && status_code < 500`","Check whether one side should test a different variable","Delete the contradictory comparison if the whole condition is dead code"],"exampleFix":"// before\nif (status_code <= 400 && status_code > 500) { /* unreachable */ }\n\n// after\nif (status_code >= 400 && status_code < 500) { /* 4xx only */ }","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":["Write all ranges as half-open `>= lo && < hi` so bounds can never contradict","When flipping an operator while editing, re-check the constants' order","Property-based or boundary tests catch unreachable conditions immediately"],"tags":["oxlint","oxc","conditions","logic-bug","javascript","static-analysis"],"backgroundTag":"impossible-range-comparison","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}