Skip to content

Commit 44bc4df

Browse files
committed
perf(linter): only check for call expr once in unicorn/no-array-method-this
1 parent 12a9934 commit 44bc4df

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
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
@@ -2984,7 +2984,8 @@ impl RuleRunner for crate::rules::unicorn::no_array_for_each::NoArrayForEach {
29842984
impl RuleRunner
29852985
for crate::rules::unicorn::no_array_method_this_argument::NoArrayMethodThisArgument
29862986
{
2987-
const NODE_TYPES: Option<&AstTypesBitset> = None;
2987+
const NODE_TYPES: Option<&AstTypesBitset> =
2988+
Some(&AstTypesBitset::from_types(&[AstType::CallExpression]));
29882989
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
29892990
}
29902991

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use oxc_ast::{
22
AstKind,
3-
ast::{Argument, Expression},
3+
ast::{Argument, CallExpression, Expression},
44
};
55
use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
@@ -56,14 +56,14 @@ declare_oxc_lint!(
5656

5757
impl Rule for NoArrayMethodThisArgument {
5858
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
59-
check_array_prototype_methods(node, ctx);
60-
check_array_from(node, ctx);
59+
let AstKind::CallExpression(call_expr) = node.kind() else { return };
60+
61+
check_array_prototype_methods(call_expr, ctx);
62+
check_array_from(call_expr, ctx);
6163
}
6264
}
6365

64-
fn check_array_prototype_methods<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) {
65-
let AstKind::CallExpression(call_expr) = node.kind() else { return };
66-
66+
fn check_array_prototype_methods(call_expr: &CallExpression, ctx: &LintContext) {
6767
if !is_method_call(
6868
call_expr,
6969
None,
@@ -96,9 +96,7 @@ fn check_array_prototype_methods<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>)
9696
));
9797
}
9898

99-
fn check_array_from<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) {
100-
let AstKind::CallExpression(call_expr) = node.kind() else { return };
101-
99+
fn check_array_from(call_expr: &CallExpression, ctx: &LintContext) {
102100
if !is_method_call(call_expr, Some(&["Array"]), Some(&["from", "fromAsync"]), Some(3), Some(3))
103101
|| call_expr.arguments.first().is_some_and(|arg| matches!(arg, Argument::SpreadElement(_)))
104102
|| call_expr.arguments.get(2).is_some_and(|arg| matches!(arg, Argument::SpreadElement(_)))

0 commit comments

Comments
 (0)