{"record":{"id":"3f7890f599f13659","repo":"oxc-project/oxc","slug":"unexpected-constant-relational-comparison","errorCode":null,"errorMessage":"Unexpected constant relational comparison","messagePattern":"Unexpected constant relational comparison","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs","lineNumber":110,"sourceCode":"            \"This compares constantly with the {left_or_right}-hand side of the {operator}\"\n        ))\n        .with_label(span)\n}\n\nfn constant_always_new(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected comparison to newly constructed object\")\n        .with_help(\"These two values can never be equal\")\n        .with_label(span)\n}\n\nfn constant_both_always_new(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected comparison of two newly constructed objects\")\n        .with_help(\"These two values can never be equal\")\n        .with_label(span)\n}\n\nfn constant_relational_comparison(operator: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected constant relational comparison\")\n        .with_help(format!(\"Both sides of the {operator} are literal values\"))\n        .with_label(span)\n}\n\nimpl Rule for NoConstantBinaryExpression {\n    fn from_configuration(value: serde_json::Value) -> Result<Self, serde_json::error::Error> {\n        DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)\n    }\n\n    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {\n        match node.kind() {\n            AstKind::LogicalExpression(expr) => match expr.operator {\n                LogicalOperator::Or | LogicalOperator::And if expr.left.is_constant(true, ctx) => {\n                    ctx.diagnostic(constant_short_circuit(\n                        \"truthiness\",\n                        expr.operator.as_str(),\n                        expr.span,\n                    ));","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs#L92-L128","documentation":"Diagnostic from `no-constant-binary-expression`, emitted by `constant_relational_comparison` (crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs:109). It fires on relational operators (`<`, `<=`, `>`, `>=`) where BOTH sides are static literals (including `-`/`+`/`~`-prefixed literals, template literals without substitutions, and global `undefined`) — e.g. `5 < 10`, `'a' < 'b'`. The compiler can fold the result, so a constant relational comparison in source is almost certainly a placeholder or mistake. It is controlled by the `checkRelationalComparisons` config, which defaults to true.","triggerScenarios":"BinaryExpression whose `operator.is_compare()` and both `left` and `right` pass `is_static_literal` — e.g. `10 >= 5`, `true >= false`, `` `foo` < `bar` ``, `null >= 5`, `-5 < 10` — with `checkRelationalComparisons: true` (the default).","commonSituations":"Minified/generated code that inlines constant comparisons; threshold constants pasted on both sides of the operator while editing; test fixtures that lint along with source; enabling the eslint `correctness` preset over previously unlinted generated files.","solutions":["Replace the constant comparison with its folded boolean result (`5 < 10` → `true`) or remove it.","If one side was meant to be a variable, restore the variable instead of the literal.","Keep constant thresholds in named bindings and compare variable-to-binding: `if (retryCount < MAX_RETRIES)`.","For generated files where literal comparisons are expected, set the rule option `{ \"checkRelationalComparisons\": false }` in .oxlintrc.json or exclude the directory."],"exampleFix":"// before\nif (5 < 10) {\n  doSomething();\n}\n\n// after\nif (retryCount < MAX_RETRIES) {\n  doSomething();\n}","handlingStrategy":"validation","validationCode":"// Gate: literal-on-both-sides relational comparisons\nconst literalRelational = /\\b(-?\\d+(\\.\\d+)?n?|['\"`][^'\"`]*['\"`]|true|false|null|undefined)\\s*[<>]=?\\s*(-?\\d+(\\.\\d+)?n?|['\"`][^'\"`]*['\"`]|true|false|null|undefined)/.test(src);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep thresholds in named constants and compare variable-to-constant.","Fold or delete literal-vs-literal comparisons during cleanup.","If generated code triggers this, set checkRelationalComparisons: false for those paths."],"tags":["lint","relational-operator","constant-folding","dead-code","oxlint"],"backgroundTag":"constant-binary-expression","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"}