@@ -3,7 +3,7 @@ use std::cmp::Ordering;
33
44use oxc_ast:: {
55 AstKind ,
6- ast:: { Expression , LogicalExpression , NumericLiteral , UnaryOperator } ,
6+ ast:: { BinaryExpression , Expression , LogicalExpression , NumericLiteral , UnaryOperator } ,
77} ;
88use oxc_diagnostics:: OxcDiagnostic ;
99use oxc_macros:: declare_oxc_lint;
@@ -111,17 +111,20 @@ declare_oxc_lint!(
111111
112112impl Rule for ConstComparisons {
113113 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
114- Self :: check_logical_expression ( node, ctx) ;
115- Self :: check_binary_expression ( node, ctx) ;
114+ match node. kind ( ) {
115+ AstKind :: LogicalExpression ( logical_expr) => {
116+ Self :: check_logical_expression ( logical_expr, ctx) ;
117+ }
118+ AstKind :: BinaryExpression ( bin_expr) => {
119+ Self :: check_binary_expression ( bin_expr, ctx) ;
120+ }
121+ _ => { }
122+ }
116123 }
117124}
118125
119126impl ConstComparisons {
120- fn check_logical_expression < ' a > ( node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
121- let AstKind :: LogicalExpression ( logical_expr) = node. kind ( ) else {
122- return ;
123- } ;
124-
127+ fn check_logical_expression < ' a > ( logical_expr : & LogicalExpression < ' a > , ctx : & LintContext < ' a > ) {
125128 Self :: check_logical_expression_const_literal_comparison ( logical_expr, ctx) ;
126129 Self :: check_redundant_logical_expression ( logical_expr, ctx) ;
127130 }
@@ -256,11 +259,7 @@ impl ConstComparisons {
256259 }
257260 }
258261
259- fn check_binary_expression < ' a > ( node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
260- let AstKind :: BinaryExpression ( bin_expr) = node. kind ( ) else {
261- return ;
262- } ;
263-
262+ fn check_binary_expression < ' a > ( bin_expr : & BinaryExpression < ' a > , ctx : & LintContext < ' a > ) {
264263 if matches ! (
265264 bin_expr. operator,
266265 BinaryOperator :: LessEqualThan
0 commit comments