Skip to content

Commit 041b2be

Browse files
committed
perf(linter): use top-level match for const-comparisons
1 parent 0f9d2ce commit 041b2be

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,8 @@ impl RuleRunner for crate::rules::oxc::branches_sharing_code::BranchesSharingCod
18591859
}
18601860

18611861
impl RuleRunner for crate::rules::oxc::const_comparisons::ConstComparisons {
1862-
const NODE_TYPES: Option<&AstTypesBitset> = None;
1862+
const NODE_TYPES: Option<&AstTypesBitset> =
1863+
Some(&AstTypesBitset::from_types(&[AstType::BinaryExpression, AstType::LogicalExpression]));
18631864
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
18641865
}
18651866

crates/oxc_linter/src/rules/oxc/const_comparisons.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp::Ordering;
33

44
use oxc_ast::{
55
AstKind,
6-
ast::{Expression, LogicalExpression, NumericLiteral, UnaryOperator},
6+
ast::{BinaryExpression, Expression, LogicalExpression, NumericLiteral, UnaryOperator},
77
};
88
use oxc_diagnostics::OxcDiagnostic;
99
use oxc_macros::declare_oxc_lint;
@@ -111,17 +111,20 @@ declare_oxc_lint!(
111111

112112
impl 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

119126
impl 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

Comments
 (0)