diff --git a/crates/oxc_linter/src/rules/oxc/const_comparisons.rs b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs index 21f17f407..66a2cf6da 100644 --- a/crates/oxc_linter/src/rules/oxc/const_comparisons.rs +++ b/crates/oxc_linter/src/rules/oxc/const_comparisons.rs @@ -16,10 +16,10 @@ use crate::{context::LintContext, rule::Rule, utils::is_same_reference, AstNode} #[derive(Debug, Error, Diagnostic)] enum ConstComparisonsDiagnostic { - #[error("oxc(const-comparisons): Unexpected redundant comparison. Left-hand side of `&&` operator has no effect")] + #[error("oxc(const-comparisons): Left-hand side of `&&` operator has no effect.")] #[diagnostic(severity(warning), help("{1}"))] RedundantLeftHandSide(#[label] Span, String), - #[error("oxc(const-comparisons): Unexpected redundant comparison. Right-hand side of `&&` operator has no effect")] + #[error("oxc(const-comparisons): Right-hand side of `&&` operator has no effect.")] #[diagnostic(severity(warning), help("{1}"))] RedundantRightHandSide(#[label] Span, String), #[error("oxc(const-comparisons): Unexpected constant comparison")] @@ -98,8 +98,8 @@ impl Rule for ConstComparisons { } if left_cmp_op.direction() == right_cmp_op.direction() { - let lhs_str = left_const_expr.value.to_string(); - let rhs_str = right_const_expr.value.to_string(); + let lhs_str = logical_expr.left.span().source_text(ctx.source_text()); + let rhs_str = logical_expr.right.span().source_text(ctx.source_text()); // We already know that either side of `&&` has no effect, // but emit a different error message depending on which side it is if left_side_is_useless(left_cmp_op, ordering) { @@ -114,8 +114,8 @@ impl Rule for ConstComparisons { )); } } else if !comparison_is_possible(left_cmp_op.direction(), ordering) { - let lhs_str = left_const_expr.value.to_string(); - let rhs_str = right_const_expr.value.to_string(); + let lhs_str = left_const_expr.span.source_text(ctx.source_text()); + let rhs_str = right_const_expr.span.source_text(ctx.source_text()); let expr_str = left_expr.span().source_text(ctx.source_text()); let diagnostic_note = match ordering { Ordering::Less => format!( diff --git a/crates/oxc_linter/src/snapshots/const_comparisons.snap b/crates/oxc_linter/src/snapshots/const_comparisons.snap index 359799c93..f2d8d6841 100644 --- a/crates/oxc_linter/src/snapshots/const_comparisons.snap +++ b/crates/oxc_linter/src/snapshots/const_comparisons.snap @@ -51,46 +51,46 @@ expression: const_comparisons ╰──── help: since `500` < `600`, the expression evaluates to false for any value of `status` - ⚠ oxc(const-comparisons): Unexpected redundant comparison. Right-hand side of `&&` operator has no effect + ⚠ oxc(const-comparisons): Right-hand side of `&&` operator has no effect. ╭─[const_comparisons.tsx:1:1] 1 │ status_code < 200 && status_code <= 299; · ─────────────────────────────────────── ╰──── - help: if `200` evaluates to true, `299` will always evaluate to true as well + help: if `status_code < 200` evaluates to true, `status_code <= 299` will always evaluate to true as well - ⚠ oxc(const-comparisons): Unexpected redundant comparison. Left-hand side of `&&` operator has no effect + ⚠ oxc(const-comparisons): Left-hand side of `&&` operator has no effect. ╭─[const_comparisons.tsx:1:1] 1 │ status_code > 200 && status_code >= 299; · ─────────────────────────────────────── ╰──── - help: if `299` evaluates to true, `200` will always evaluate to true as well + help: if `status_code >= 299` evaluates to true, `status_code > 200` will always evaluate to true as well - ⚠ oxc(const-comparisons): Unexpected redundant comparison. Left-hand side of `&&` operator has no effect + ⚠ oxc(const-comparisons): Left-hand side of `&&` operator has no effect. ╭─[const_comparisons.tsx:1:1] 1 │ status_code >= 500 && status_code > 500; · ─────────────────────────────────────── ╰──── - help: if `500` evaluates to true, `500` will always evaluate to true as well + help: if `status_code > 500` evaluates to true, `status_code >= 500` will always evaluate to true as well - ⚠ oxc(const-comparisons): Unexpected redundant comparison. Right-hand side of `&&` operator has no effect + ⚠ oxc(const-comparisons): Right-hand side of `&&` operator has no effect. ╭─[const_comparisons.tsx:1:1] 1 │ status_code > 500 && status_code >= 500; · ─────────────────────────────────────── ╰──── - help: if `500` evaluates to true, `500` will always evaluate to true as well + help: if `status_code > 500` evaluates to true, `status_code >= 500` will always evaluate to true as well - ⚠ oxc(const-comparisons): Unexpected redundant comparison. Left-hand side of `&&` operator has no effect + ⚠ oxc(const-comparisons): Left-hand side of `&&` operator has no effect. ╭─[const_comparisons.tsx:1:1] 1 │ status_code <= 500 && status_code < 500; · ─────────────────────────────────────── ╰──── - help: if `500` evaluates to true, `500` will always evaluate to true as well + help: if `status_code < 500` evaluates to true, `status_code <= 500` will always evaluate to true as well - ⚠ oxc(const-comparisons): Unexpected redundant comparison. Right-hand side of `&&` operator has no effect + ⚠ oxc(const-comparisons): Right-hand side of `&&` operator has no effect. ╭─[const_comparisons.tsx:1:1] 1 │ status_code < 500 && status_code <= 500; · ─────────────────────────────────────── ╰──── - help: if `500` evaluates to true, `500` will always evaluate to true as well + help: if `status_code < 500` evaluates to true, `status_code <= 500` will always evaluate to true as well