Skip to content

Commit 07db921

Browse files
committed
perf(linter): update catch-error-name to use top-level match (#14698)
Top-level `match` is simpler and enables node type analysis in the linter codegen.
1 parent 2582a50 commit 07db921

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
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
@@ -2949,7 +2949,8 @@ impl RuleRunner for crate::rules::typescript::use_unknown_in_catch_callback_vari
29492949
}
29502950

29512951
impl RuleRunner for crate::rules::unicorn::catch_error_name::CatchErrorName {
2952-
const NODE_TYPES: Option<&AstTypesBitset> = None;
2952+
const NODE_TYPES: Option<&AstTypesBitset> =
2953+
Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::CatchParameter]));
29532954
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
29542955
}
29552956

crates/oxc_linter/src/rules/unicorn/catch_error_name.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,26 @@ impl Rule for CatchErrorName {
152152
}
153153

154154
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
155-
if let AstKind::CatchParameter(catch_param) = node.kind() {
156-
self.check_binding_identifier(ctx, &catch_param.pattern.kind);
157-
}
158-
159-
if let AstKind::CallExpression(call_expr) = node.kind()
160-
&& let Some(member_expr) = call_expr.callee.as_member_expression()
161-
{
162-
if member_expr.static_property_name() == Some("catch")
163-
&& let Some(arg) = call_expr.arguments.first()
164-
{
165-
self.check_function_arguments(arg, ctx);
155+
match node.kind() {
156+
AstKind::CatchParameter(catch_param) => {
157+
self.check_binding_identifier(ctx, &catch_param.pattern.kind);
166158
}
159+
AstKind::CallExpression(call_expr) => {
160+
if let Some(member_expr) = call_expr.callee.as_member_expression() {
161+
if member_expr.static_property_name() == Some("catch")
162+
&& let Some(arg) = call_expr.arguments.first()
163+
{
164+
self.check_function_arguments(arg, ctx);
165+
}
167166

168-
if member_expr.static_property_name() == Some("then")
169-
&& let Some(arg) = call_expr.arguments.get(1)
170-
{
171-
self.check_function_arguments(arg, ctx);
167+
if member_expr.static_property_name() == Some("then")
168+
&& let Some(arg) = call_expr.arguments.get(1)
169+
{
170+
self.check_function_arguments(arg, ctx);
171+
}
172+
}
172173
}
174+
_ => {}
173175
}
174176
}
175177
}

0 commit comments

Comments
 (0)