Skip to content

Commit d6609e9

Browse files
committedOct 21, 2024·
refactor(linter): use run_on_jest_node for existing lint rules (#6722)
- closes #6038 Migrates all simple iterations over Jest nodes to use the `run_on_jest_node` method. Rules which require more custom data (such as getting nodes in order or storing data about counts, duplicates, etc.) have not been migrated. Some simple benchmarking shows that this is ~5% faster on `vscode` when the Jest/Vitest rules are NOT enabled (due to being able to skip them now). And it is up to 8% on `vscode` when the Jest/Vitest plugins are enabled. ``` hyperfine -i -N --warmup 3 --runs 30 './oxlint-jest-iter --deny=all --silent ./vscode' './oxlint-main --deny=all --silent ./vscode' Benchmark 1: ./oxlint-jest-iter --deny=all --silent ./vscode Time (mean ± σ): 2.348 s ± 0.104 s [User: 16.922 s, System: 0.641 s] Range (min … max): 2.141 s … 2.544 s 30 runs Benchmark 2: ./oxlint-main --deny=all --silent ./vscode Time (mean ± σ): 2.476 s ± 0.042 s [User: 17.768 s, System: 0.668 s] Range (min … max): 2.430 s … 2.598 s 30 runs Summary ./oxlint-jest-iter --deny=all --silent ./vscode ran 1.05 ± 0.05 times faster than ./oxlint-main --deny=all --silent ./vscode ``` ``` hyperfine -i -N --warmup 3 --runs 30 './oxlint-jest-iter --deny=all --jest-plugin --vitest-plugin --silent ./vscode' './oxlint-main --deny=all --jest-plugin --vitest-plugin --silent ./vscode' Benchmark 1: ./oxlint-jest-iter --deny=all --jest-plugin --vitest-plugin --silent ./vscode Time (mean ± σ): 2.728 s ± 0.118 s [User: 19.782 s, System: 0.786 s] Range (min … max): 2.580 s … 3.078 s 30 runs Benchmark 2: ./oxlint-main --deny=all --jest-plugin --vitest-plugin --silent ./vscode Time (mean ± σ): 2.939 s ± 0.051 s [User: 21.259 s, System: 0.859 s] Range (min … max): 2.848 s … 3.064 s 30 runs Summary ./oxlint-jest-iter --deny=all --jest-plugin --vitest-plugin --silent ./vscode ran 1.08 ± 0.05 times faster than ./oxlint-main --deny=all --jest-plugin --vitest-plugin --silent ./vscode ```
1 parent 97195ec commit d6609e9

35 files changed

+243
-213
lines changed
 

‎apps/oxlint/src/lint/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ mod test {
539539
let args = &[
540540
"-c",
541541
"fixtures/eslintrc_vitest_replace/eslintrc.json",
542-
"fixtures/eslintrc_vitest_replace/foo.js",
542+
"fixtures/eslintrc_vitest_replace/foo.test.js",
543543
];
544544
let result = test(args);
545545
assert_eq!(result.number_of_files, 1);
@@ -549,7 +549,7 @@ mod test {
549549
"--vitest-plugin",
550550
"-c",
551551
"fixtures/eslintrc_vitest_replace/eslintrc.json",
552-
"fixtures/eslintrc_vitest_replace/foo.js",
552+
"fixtures/eslintrc_vitest_replace/foo.test.js",
553553
];
554554
let result = test(args);
555555
assert_eq!(result.number_of_files, 1);

‎crates/oxc_linter/src/rules/jest/expect_expect.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use crate::{
1414
context::LintContext,
1515
rule::Rule,
1616
utils::{
17-
collect_possible_jest_call_node, get_node_name, is_type_of_jest_fn_call, JestFnKind,
18-
JestGeneralFnKind, PossibleJestNode,
17+
get_node_name, is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode,
1918
},
2019
};
2120

@@ -107,10 +106,12 @@ impl Rule for ExpectExpect {
107106
}))
108107
}
109108

110-
fn run_once(&self, ctx: &LintContext) {
111-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
112-
run(self, possible_jest_node, ctx);
113-
}
109+
fn run_on_jest_node<'a, 'c>(
110+
&self,
111+
jest_node: &PossibleJestNode<'a, 'c>,
112+
ctx: &'c LintContext<'a>,
113+
) {
114+
run(self, jest_node, ctx);
114115
}
115116
}
116117

‎crates/oxc_linter/src/rules/jest/no_alias_methods.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use oxc_span::Span;
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
9+
utils::{parse_expect_jest_fn_call, PossibleJestNode},
1010
};
1111

1212
fn no_alias_methods_diagnostic(x1: &str, x2: &str, span3: Span) -> OxcDiagnostic {
@@ -59,10 +59,12 @@ declare_oxc_lint!(
5959
);
6060

6161
impl Rule for NoAliasMethods {
62-
fn run_once(&self, ctx: &LintContext) {
63-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
64-
run(possible_jest_node, ctx);
65-
}
62+
fn run_on_jest_node<'a, 'c>(
63+
&self,
64+
jest_node: &PossibleJestNode<'a, 'c>,
65+
ctx: &'c LintContext<'a>,
66+
) {
67+
run(jest_node, ctx);
6668
}
6769
}
6870

‎crates/oxc_linter/src/rules/jest/no_conditional_expect.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::{
99
context::LintContext,
1010
rule::Rule,
1111
utils::{
12-
collect_possible_jest_call_node, is_type_of_jest_fn_call, parse_expect_jest_fn_call,
13-
JestFnKind, JestGeneralFnKind, PossibleJestNode,
12+
is_type_of_jest_fn_call, parse_expect_jest_fn_call, JestFnKind, JestGeneralFnKind,
13+
PossibleJestNode,
1414
},
1515
};
1616

@@ -70,10 +70,12 @@ declare_oxc_lint!(
7070
struct InConditional(bool);
7171

7272
impl Rule for NoConditionalExpect {
73-
fn run_once(&self, ctx: &LintContext) {
74-
for node in &collect_possible_jest_call_node(ctx) {
75-
run(node, ctx);
76-
}
73+
fn run_on_jest_node<'a, 'c>(
74+
&self,
75+
jest_node: &PossibleJestNode<'a, 'c>,
76+
ctx: &'c LintContext<'a>,
77+
) {
78+
run(jest_node, ctx);
7779
}
7880
}
7981

‎crates/oxc_linter/src/rules/jest/no_disabled_tests.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
context::LintContext,
88
rule::Rule,
99
utils::{
10-
collect_possible_jest_call_node, parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind,
11-
ParsedGeneralJestFnCall, PossibleJestNode,
10+
parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind, ParsedGeneralJestFnCall,
11+
PossibleJestNode,
1212
},
1313
};
1414

@@ -90,10 +90,12 @@ impl Message {
9090
}
9191

9292
impl Rule for NoDisabledTests {
93-
fn run_once(&self, ctx: &LintContext) {
94-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
95-
run(possible_jest_node, ctx);
96-
}
93+
fn run_on_jest_node<'a, 'c>(
94+
&self,
95+
jest_node: &PossibleJestNode<'a, 'c>,
96+
ctx: &'c LintContext<'a>,
97+
) {
98+
run(jest_node, ctx);
9799
}
98100
}
99101

‎crates/oxc_linter/src/rules/jest/no_done_callback.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::{
1010
context::LintContext,
1111
rule::Rule,
1212
utils::{
13-
collect_possible_jest_call_node, get_node_name, parse_general_jest_fn_call, JestFnKind,
14-
JestGeneralFnKind, PossibleJestNode,
13+
get_node_name, parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode,
1514
},
1615
};
1716

@@ -77,10 +76,12 @@ declare_oxc_lint!(
7776
);
7877

7978
impl Rule for NoDoneCallback {
80-
fn run_once(&self, ctx: &LintContext) {
81-
for node in &collect_possible_jest_call_node(ctx) {
82-
run(node, ctx);
83-
}
79+
fn run_on_jest_node<'a, 'c>(
80+
&self,
81+
jest_node: &PossibleJestNode<'a, 'c>,
82+
ctx: &'c LintContext<'a>,
83+
) {
84+
run(jest_node, ctx);
8485
}
8586
}
8687

‎crates/oxc_linter/src/rules/jest/no_focused_tests.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
context::LintContext,
88
rule::Rule,
99
utils::{
10-
collect_possible_jest_call_node, parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind,
11-
MemberExpressionElement, ParsedGeneralJestFnCall, PossibleJestNode,
10+
parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind, MemberExpressionElement,
11+
ParsedGeneralJestFnCall, PossibleJestNode,
1212
},
1313
};
1414

@@ -66,10 +66,12 @@ declare_oxc_lint!(
6666
);
6767

6868
impl Rule for NoFocusedTests {
69-
fn run_once(&self, ctx: &LintContext) {
70-
for node in &collect_possible_jest_call_node(ctx) {
71-
run(node, ctx);
72-
}
69+
fn run_on_jest_node<'a, 'c>(
70+
&self,
71+
jest_node: &PossibleJestNode<'a, 'c>,
72+
ctx: &'c LintContext<'a>,
73+
) {
74+
run(jest_node, ctx);
7375
}
7476
}
7577

‎crates/oxc_linter/src/rules/jest/no_hooks.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use oxc_span::{CompactStr, GetSpan, Span};
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{
10-
collect_possible_jest_call_node, is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind,
11-
PossibleJestNode,
12-
},
9+
utils::{is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
1310
};
1411

1512
fn unexpected_hook_diagonsitc(span: Span) -> OxcDiagnostic {
@@ -96,10 +93,12 @@ impl Rule for NoHooks {
9693
Self(Box::new(NoHooksConfig { allow }))
9794
}
9895

99-
fn run_once(&self, ctx: &LintContext) {
100-
for possible_jest_node in collect_possible_jest_call_node(ctx) {
101-
self.run(&possible_jest_node, ctx);
102-
}
96+
fn run_on_jest_node<'a, 'c>(
97+
&self,
98+
jest_node: &PossibleJestNode<'a, 'c>,
99+
ctx: &'c LintContext<'a>,
100+
) {
101+
self.run(jest_node, ctx);
103102
}
104103
}
105104

‎crates/oxc_linter/src/rules/jest/no_interpolation_in_snapshots.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use oxc_span::Span;
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
9+
utils::{parse_expect_jest_fn_call, PossibleJestNode},
1010
};
1111

1212
fn no_interpolation_in_snapshots_diagnostic(span: Span) -> OxcDiagnostic {
@@ -55,10 +55,12 @@ declare_oxc_lint!(
5555
);
5656

5757
impl Rule for NoInterpolationInSnapshots {
58-
fn run_once(&self, ctx: &LintContext) {
59-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
60-
run(possible_jest_node, ctx);
61-
}
58+
fn run_on_jest_node<'a, 'c>(
59+
&self,
60+
jest_node: &PossibleJestNode<'a, 'c>,
61+
ctx: &'c LintContext<'a>,
62+
) {
63+
run(jest_node, ctx);
6264
}
6365
}
6466

‎crates/oxc_linter/src/rules/jest/no_large_snapshots.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hash::FxHashMap;
1313
use crate::{
1414
context::LintContext,
1515
rule::Rule,
16-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
16+
utils::{iter_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
1717
};
1818

1919
// TODO: re-word diagnostic messages
@@ -167,8 +167,8 @@ impl Rule for NoLargeSnapshots {
167167
}
168168
}
169169
} else {
170-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
171-
self.run(possible_jest_node, ctx);
170+
for possible_jest_node in iter_possible_jest_call_node(ctx.semantic()) {
171+
self.run(&possible_jest_node, ctx);
172172
}
173173
}
174174
}

‎crates/oxc_linter/src/rules/jest/no_restricted_jest_methods.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use rustc_hash::FxHashMap;
77
use crate::{
88
context::LintContext,
99
rule::Rule,
10-
utils::{
11-
collect_possible_jest_call_node, is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind,
12-
PossibleJestNode,
13-
},
10+
utils::{is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
1411
};
1512

1613
fn restricted_jest_method(x0: &str, span1: Span) -> OxcDiagnostic {
@@ -76,10 +73,12 @@ impl Rule for NoRestrictedJestMethods {
7673
}))
7774
}
7875

79-
fn run_once(&self, ctx: &LintContext) {
80-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
81-
self.run(possible_jest_node, ctx);
82-
}
76+
fn run_on_jest_node<'a, 'c>(
77+
&self,
78+
jest_node: &PossibleJestNode<'a, 'c>,
79+
ctx: &'c LintContext<'a>,
80+
) {
81+
self.run(jest_node, ctx);
8382
}
8483
}
8584

‎crates/oxc_linter/src/rules/jest/no_restricted_matchers.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{
1111
context::LintContext,
1212
rule::Rule,
1313
utils::{
14-
collect_possible_jest_call_node, is_type_of_jest_fn_call, parse_expect_jest_fn_call,
15-
JestFnKind, KnownMemberExpressionProperty, PossibleJestNode,
14+
is_type_of_jest_fn_call, parse_expect_jest_fn_call, JestFnKind,
15+
KnownMemberExpressionProperty, PossibleJestNode,
1616
},
1717
};
1818

@@ -90,10 +90,12 @@ impl Rule for NoRestrictedMatchers {
9090
}))
9191
}
9292

93-
fn run_once(&self, ctx: &LintContext<'_>) {
94-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
95-
self.run(possible_jest_node, ctx);
96-
}
93+
fn run_on_jest_node<'a, 'c>(
94+
&self,
95+
jest_node: &PossibleJestNode<'a, 'c>,
96+
ctx: &'c LintContext<'a>,
97+
) {
98+
self.run(jest_node, ctx);
9799
}
98100
}
99101

‎crates/oxc_linter/src/rules/jest/no_test_prefixes.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
context::LintContext,
88
rule::Rule,
99
utils::{
10-
collect_possible_jest_call_node, parse_general_jest_fn_call, JestGeneralFnKind,
11-
KnownMemberExpressionProperty, ParsedGeneralJestFnCall, PossibleJestNode,
10+
parse_general_jest_fn_call, JestGeneralFnKind, KnownMemberExpressionProperty,
11+
ParsedGeneralJestFnCall, PossibleJestNode,
1212
},
1313
};
1414

@@ -58,10 +58,12 @@ declare_oxc_lint!(
5858
);
5959

6060
impl Rule for NoTestPrefixes {
61-
fn run_once(&self, ctx: &LintContext) {
62-
for node in &collect_possible_jest_call_node(ctx) {
63-
run(node, ctx);
64-
}
61+
fn run_on_jest_node<'a, 'c>(
62+
&self,
63+
jest_node: &PossibleJestNode<'a, 'c>,
64+
ctx: &'c LintContext<'a>,
65+
) {
66+
run(jest_node, ctx);
6567
}
6668
}
6769

‎crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
77
use oxc_span::Span;
88

9-
use crate::{
10-
context::LintContext,
11-
rule::Rule,
12-
utils::{collect_possible_jest_call_node, PossibleJestNode},
13-
};
9+
use crate::{context::LintContext, rule::Rule, utils::PossibleJestNode};
1410

1511
fn add_type_parameter_to_module_mock_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
1612
OxcDiagnostic::warn(
@@ -92,10 +88,12 @@ declare_oxc_lint!(
9288
);
9389

9490
impl Rule for NoUntypedMockFactory {
95-
fn run_once(&self, ctx: &LintContext<'_>) {
96-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
97-
Self::run(possible_jest_node, ctx);
98-
}
91+
fn run_on_jest_node<'a, 'c>(
92+
&self,
93+
jest_node: &PossibleJestNode<'a, 'c>,
94+
ctx: &'c LintContext<'a>,
95+
) {
96+
Self::run(jest_node, ctx);
9997
}
10098

10199
fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {

‎crates/oxc_linter/src/rules/jest/prefer_called_with.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use oxc_span::Span;
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
9+
utils::{parse_expect_jest_fn_call, PossibleJestNode},
1010
};
1111

1212
fn use_to_be_called_with(span: Span) -> OxcDiagnostic {
@@ -48,10 +48,12 @@ declare_oxc_lint!(
4848
);
4949

5050
impl Rule for PreferCalledWith {
51-
fn run_once(&self, ctx: &LintContext<'_>) {
52-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
53-
Self::run(possible_jest_node, ctx);
54-
}
51+
fn run_on_jest_node<'a, 'c>(
52+
&self,
53+
jest_node: &PossibleJestNode<'a, 'c>,
54+
ctx: &'c LintContext<'a>,
55+
) {
56+
Self::run(jest_node, ctx);
5557
}
5658
}
5759

‎crates/oxc_linter/src/rules/jest/prefer_comparison_matcher.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
fixer::RuleFixer,
1313
rule::Rule,
1414
utils::{
15-
collect_possible_jest_call_node, is_equality_matcher, parse_expect_jest_fn_call,
16-
KnownMemberExpressionProperty, PossibleJestNode,
15+
is_equality_matcher, parse_expect_jest_fn_call, KnownMemberExpressionProperty,
16+
PossibleJestNode,
1717
},
1818
};
1919

@@ -60,10 +60,12 @@ declare_oxc_lint!(
6060
);
6161

6262
impl Rule for PreferComparisonMatcher {
63-
fn run_once(&self, ctx: &LintContext) {
64-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
65-
Self::run(possible_jest_node, ctx);
66-
}
63+
fn run_on_jest_node<'a, 'c>(
64+
&self,
65+
jest_node: &PossibleJestNode<'a, 'c>,
66+
ctx: &'c LintContext<'a>,
67+
) {
68+
Self::run(jest_node, ctx);
6769
}
6870
}
6971

‎crates/oxc_linter/src/rules/jest/prefer_equality_matcher.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use oxc_syntax::operator::BinaryOperator;
1010
use crate::{
1111
context::LintContext,
1212
rule::Rule,
13-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
13+
utils::{parse_expect_jest_fn_call, PossibleJestNode},
1414
};
1515

1616
fn use_equality_matcher_diagnostic(span: Span) -> OxcDiagnostic {
@@ -45,10 +45,12 @@ declare_oxc_lint!(
4545
);
4646

4747
impl Rule for PreferEqualityMatcher {
48-
fn run_once(&self, ctx: &LintContext) {
49-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
50-
Self::run(possible_jest_node, ctx);
51-
}
48+
fn run_on_jest_node<'a, 'c>(
49+
&self,
50+
jest_node: &PossibleJestNode<'a, 'c>,
51+
ctx: &'c LintContext<'a>,
52+
) {
53+
Self::run(jest_node, ctx);
5254
}
5355
}
5456

‎crates/oxc_linter/src/rules/jest/prefer_expect_resolves.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use crate::{
1010
context::LintContext,
1111
fixer::{RuleFix, RuleFixer},
1212
rule::Rule,
13-
utils::{
14-
collect_possible_jest_call_node, parse_expect_jest_fn_call, ParsedExpectFnCall,
15-
PossibleJestNode,
16-
},
13+
utils::{parse_expect_jest_fn_call, ParsedExpectFnCall, PossibleJestNode},
1714
};
1815

1916
fn expect_resolves(span: Span) -> OxcDiagnostic {
@@ -76,10 +73,12 @@ declare_oxc_lint!(
7673
);
7774

7875
impl Rule for PreferExpectResolves {
79-
fn run_once(&self, ctx: &LintContext) {
80-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
81-
Self::run(possible_jest_node, ctx);
82-
}
76+
fn run_on_jest_node<'a, 'c>(
77+
&self,
78+
jest_node: &PossibleJestNode<'a, 'c>,
79+
ctx: &'c LintContext<'a>,
80+
) {
81+
Self::run(jest_node, ctx);
8382
}
8483
}
8584

‎crates/oxc_linter/src/rules/jest/prefer_lowercase_title.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use crate::{
77
context::LintContext,
88
rule::Rule,
99
utils::{
10-
collect_possible_jest_call_node, parse_jest_fn_call, JestFnKind, JestGeneralFnKind,
11-
ParsedJestFnCallNew, PossibleJestNode,
10+
parse_jest_fn_call, JestFnKind, JestGeneralFnKind, ParsedJestFnCallNew, PossibleJestNode,
1211
},
1312
};
1413

@@ -157,10 +156,12 @@ impl Rule for PreferLowercaseTitle {
157156
}))
158157
}
159158

160-
fn run_once(&self, ctx: &LintContext) {
161-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
162-
self.run(possible_jest_node, ctx);
163-
}
159+
fn run_on_jest_node<'a, 'c>(
160+
&self,
161+
jest_node: &PossibleJestNode<'a, 'c>,
162+
ctx: &'c LintContext<'a>,
163+
) {
164+
self.run(jest_node, ctx);
164165
}
165166
}
166167

‎crates/oxc_linter/src/rules/jest/prefer_strict_equal.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use oxc_span::Span;
55
use crate::{
66
context::LintContext,
77
rule::Rule,
8-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
8+
utils::{parse_expect_jest_fn_call, PossibleJestNode},
99
};
1010

1111
fn use_to_strict_equal(span: Span) -> OxcDiagnostic {
@@ -38,10 +38,12 @@ declare_oxc_lint!(
3838
);
3939

4040
impl Rule for PreferStrictEqual {
41-
fn run_once(&self, ctx: &LintContext) {
42-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
43-
Self::run(possible_jest_node, ctx);
44-
}
41+
fn run_on_jest_node<'a, 'c>(
42+
&self,
43+
jest_node: &PossibleJestNode<'a, 'c>,
44+
ctx: &'c LintContext<'a>,
45+
) {
46+
Self::run(jest_node, ctx);
4547
}
4648
}
4749

‎crates/oxc_linter/src/rules/jest/prefer_to_be.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
context::LintContext,
1111
rule::Rule,
1212
utils::{
13-
collect_possible_jest_call_node, is_equality_matcher, parse_expect_jest_fn_call,
14-
KnownMemberExpressionProperty, ParsedExpectFnCall, PossibleJestNode,
13+
is_equality_matcher, parse_expect_jest_fn_call, KnownMemberExpressionProperty,
14+
ParsedExpectFnCall, PossibleJestNode,
1515
},
1616
};
1717

@@ -79,10 +79,12 @@ enum PreferToBeKind {
7979
}
8080

8181
impl Rule for PreferToBe {
82-
fn run_once(&self, ctx: &LintContext) {
83-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
84-
Self::run(possible_jest_node, ctx);
85-
}
82+
fn run_on_jest_node<'a, 'c>(
83+
&self,
84+
jest_node: &PossibleJestNode<'a, 'c>,
85+
ctx: &'c LintContext<'a>,
86+
) {
87+
Self::run(jest_node, ctx);
8688
}
8789
}
8890

‎crates/oxc_linter/src/rules/jest/prefer_to_contain.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
context::LintContext,
1111
rule::Rule,
1212
utils::{
13-
collect_possible_jest_call_node, is_equality_matcher, parse_expect_jest_fn_call,
14-
KnownMemberExpressionParentKind, PossibleJestNode,
13+
is_equality_matcher, parse_expect_jest_fn_call, KnownMemberExpressionParentKind,
14+
PossibleJestNode,
1515
},
1616
};
1717

@@ -53,10 +53,12 @@ declare_oxc_lint!(
5353
);
5454

5555
impl Rule for PreferToContain {
56-
fn run_once(&self, ctx: &LintContext) {
57-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
58-
Self::run(possible_jest_node, ctx);
59-
}
56+
fn run_on_jest_node<'a, 'c>(
57+
&self,
58+
jest_node: &PossibleJestNode<'a, 'c>,
59+
ctx: &'c LintContext<'a>,
60+
) {
61+
Self::run(jest_node, ctx);
6062
}
6163
}
6264

‎crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use crate::{
1010
context::LintContext,
1111
fixer::RuleFixer,
1212
rule::Rule,
13-
utils::{
14-
collect_possible_jest_call_node, is_equality_matcher, parse_expect_jest_fn_call,
15-
ParsedExpectFnCall, PossibleJestNode,
16-
},
13+
utils::{is_equality_matcher, parse_expect_jest_fn_call, ParsedExpectFnCall, PossibleJestNode},
1714
};
1815

1916
fn use_to_have_length(span: Span) -> OxcDiagnostic {
@@ -55,10 +52,12 @@ declare_oxc_lint!(
5552
);
5653

5754
impl Rule for PreferToHaveLength {
58-
fn run_once(&self, ctx: &LintContext) {
59-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
60-
Self::run(possible_jest_node, ctx);
61-
}
55+
fn run_on_jest_node<'a, 'c>(
56+
&self,
57+
jest_node: &PossibleJestNode<'a, 'c>,
58+
ctx: &'c LintContext<'a>,
59+
) {
60+
Self::run(jest_node, ctx);
6261
}
6362
}
6463

‎crates/oxc_linter/src/rules/jest/prefer_todo.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use crate::{
1010
context::LintContext,
1111
fixer::{RuleFix, RuleFixer},
1212
rule::Rule,
13-
utils::{
14-
collect_possible_jest_call_node, is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind,
15-
PossibleJestNode,
16-
},
13+
utils::{is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
1714
};
1815

1916
fn empty_test(span: Span) -> OxcDiagnostic {
@@ -51,10 +48,12 @@ declare_oxc_lint!(
5148
);
5249

5350
impl Rule for PreferTodo {
54-
fn run_once(&self, ctx: &LintContext) {
55-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
56-
run(possible_jest_node, ctx);
57-
}
51+
fn run_on_jest_node<'a, 'c>(
52+
&self,
53+
jest_node: &PossibleJestNode<'a, 'c>,
54+
ctx: &'c LintContext<'a>,
55+
) {
56+
run(jest_node, ctx);
5857
}
5958
}
6059

‎crates/oxc_linter/src/rules/jest/require_to_throw_message.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use oxc_span::Span;
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{collect_possible_jest_call_node, parse_expect_jest_fn_call, PossibleJestNode},
9+
utils::{parse_expect_jest_fn_call, PossibleJestNode},
1010
};
1111

1212
fn require_to_throw_message_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic {
@@ -46,10 +46,12 @@ declare_oxc_lint!(
4646
);
4747

4848
impl Rule for RequireToThrowMessage {
49-
fn run_once(&self, ctx: &LintContext) {
50-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
51-
Self::run(possible_jest_node, ctx);
52-
}
49+
fn run_on_jest_node<'a, 'c>(
50+
&self,
51+
jest_node: &PossibleJestNode<'a, 'c>,
52+
ctx: &'c LintContext<'a>,
53+
) {
54+
Self::run(jest_node, ctx);
5355
}
5456
}
5557

@@ -177,5 +179,5 @@ fn test() {
177179
),
178180
];
179181

180-
Tester::new(RequireToThrowMessage::NAME, pass, fail).test_and_snapshot();
182+
Tester::new(RequireToThrowMessage::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
181183
}

‎crates/oxc_linter/src/rules/jest/valid_describe_callback.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use oxc_span::{GetSpan, Span};
99
use crate::{
1010
context::LintContext,
1111
rule::Rule,
12-
utils::{
13-
collect_possible_jest_call_node, parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind,
14-
PossibleJestNode,
15-
},
12+
utils::{parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
1613
};
1714

1815
fn valid_describe_callback_diagnostic(
@@ -76,10 +73,12 @@ declare_oxc_lint!(
7673
);
7774

7875
impl Rule for ValidDescribeCallback {
79-
fn run_once(&self, ctx: &LintContext) {
80-
for node in &collect_possible_jest_call_node(ctx) {
81-
run(node, ctx);
82-
}
76+
fn run_on_jest_node<'a, 'c>(
77+
&self,
78+
jest_node: &PossibleJestNode<'a, 'c>,
79+
ctx: &'c LintContext<'a>,
80+
) {
81+
run(jest_node, ctx);
8382
}
8483
}
8584

‎crates/oxc_linter/src/rules/jest/valid_expect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use oxc_span::{GetSpan, Span};
1111
use crate::{
1212
context::LintContext,
1313
rule::Rule,
14-
utils::{
15-
collect_possible_jest_call_node, parse_expect_jest_fn_call, ExpectError, PossibleJestNode,
16-
},
14+
utils::{parse_expect_jest_fn_call, ExpectError, PossibleJestNode},
1715
AstNode,
1816
};
1917

@@ -115,10 +113,12 @@ impl Rule for ValidExpect {
115113
Self(Box::new(ValidExpectConfig { async_matchers, min_args, max_args, always_await }))
116114
}
117115

118-
fn run_once(&self, ctx: &LintContext) {
119-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
120-
self.run(possible_jest_node, ctx);
121-
}
116+
fn run_on_jest_node<'a, 'b>(
117+
&self,
118+
jest_node: &PossibleJestNode<'a, 'b>,
119+
ctx: &'b LintContext<'a>,
120+
) {
121+
self.run(jest_node, ctx);
122122
}
123123
}
124124

‎crates/oxc_linter/src/rules/jest/valid_title.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ use rustc_hash::FxHashMap;
1414
use crate::{
1515
context::LintContext,
1616
rule::Rule,
17-
utils::{
18-
collect_possible_jest_call_node, parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind,
19-
PossibleJestNode,
20-
},
17+
utils::{parse_general_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
2118
};
2219

2320
fn valid_title_diagnostic(x0: &str, x1: &str, span2: Span) -> OxcDiagnostic {
@@ -105,10 +102,12 @@ impl Rule for ValidTitle {
105102
}))
106103
}
107104

108-
fn run_once(&self, ctx: &LintContext) {
109-
for node in &collect_possible_jest_call_node(ctx) {
110-
self.run(node, ctx);
111-
}
105+
fn run_on_jest_node<'a, 'c>(
106+
&self,
107+
jest_node: &PossibleJestNode<'a, 'c>,
108+
ctx: &'c LintContext<'a>,
109+
) {
110+
self.run(jest_node, ctx);
112111
}
113112
}
114113

‎crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use oxc_span::Span;
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{
10-
collect_possible_jest_call_node, is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind,
11-
PossibleJestNode,
12-
},
9+
utils::{is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
1310
};
1411

1512
fn no_conditional_tests(span: Span) -> OxcDiagnostic {
@@ -59,10 +56,12 @@ declare_oxc_lint!(
5956
);
6057

6158
impl Rule for NoConditionalTests {
62-
fn run_once(&self, ctx: &LintContext) {
63-
for node in &collect_possible_jest_call_node(ctx) {
64-
run(node, ctx);
65-
}
59+
fn run_on_jest_node<'a, 'c>(
60+
&self,
61+
jest_node: &PossibleJestNode<'a, 'c>,
62+
ctx: &'c LintContext<'a>,
63+
) {
64+
run(jest_node, ctx);
6665
}
6766
}
6867

@@ -142,5 +141,5 @@ fn test() {
142141
});"#,
143142
];
144143

145-
Tester::new(NoConditionalTests::NAME, pass, fail).test_and_snapshot();
144+
Tester::new(NoConditionalTests::NAME, pass, fail).with_vitest_plugin(true).test_and_snapshot();
146145
}

‎crates/oxc_linter/src/rules/vitest/prefer_to_be_falsy.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use oxc_macros::declare_oxc_lint;
22

3-
use crate::{context::LintContext, rule::Rule, utils::collect_possible_jest_call_node};
3+
use crate::{context::LintContext, rule::Rule};
44

55
use super::prefer_to_be_truthy::prefer_to_be_simply_bool;
66

@@ -38,10 +38,12 @@ declare_oxc_lint!(
3838
);
3939

4040
impl Rule for PreferToBeFalsy {
41-
fn run_once(&self, ctx: &LintContext) {
42-
for possible_vitest_node in &collect_possible_jest_call_node(ctx) {
43-
prefer_to_be_simply_bool(possible_vitest_node, ctx, false);
44-
}
41+
fn run_on_jest_node<'a, 'c>(
42+
&self,
43+
jest_node: &crate::utils::PossibleJestNode<'a, 'c>,
44+
ctx: &'c LintContext<'a>,
45+
) {
46+
prefer_to_be_simply_bool(jest_node, ctx, false);
4547
}
4648
}
4749

@@ -100,5 +102,8 @@ fn test() {
100102
None,
101103
),
102104
];
103-
Tester::new(PreferToBeFalsy::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
105+
Tester::new(PreferToBeFalsy::NAME, pass, fail)
106+
.expect_fix(fix)
107+
.with_vitest_plugin(true)
108+
.test_and_snapshot();
104109
}

‎crates/oxc_linter/src/rules/vitest/prefer_to_be_object.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{
1010
context::LintContext,
1111
rule::Rule,
1212
utils::{
13-
collect_possible_jest_call_node, parse_jest_fn_call, KnownMemberExpressionProperty,
14-
ParsedExpectFnCall, ParsedJestFnCallNew, PossibleJestNode,
13+
parse_jest_fn_call, KnownMemberExpressionProperty, ParsedExpectFnCall, ParsedJestFnCallNew,
14+
PossibleJestNode,
1515
},
1616
};
1717

@@ -66,10 +66,12 @@ declare_oxc_lint!(
6666
);
6767

6868
impl Rule for PreferToBeObject {
69-
fn run_once(&self, ctx: &LintContext) {
70-
for possible_vitest_node in &collect_possible_jest_call_node(ctx) {
71-
Self::run(possible_vitest_node, ctx);
72-
}
69+
fn run_on_jest_node<'a, 'c>(
70+
&self,
71+
jest_node: &PossibleJestNode<'a, 'c>,
72+
ctx: &'c LintContext<'a>,
73+
) {
74+
Self::run(jest_node, ctx);
7375
}
7476
}
7577

‎crates/oxc_linter/src/rules/vitest/prefer_to_be_truthy.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use oxc_macros::declare_oxc_lint;
77
use crate::{
88
context::LintContext,
99
rule::Rule,
10-
utils::{
11-
collect_possible_jest_call_node, is_equality_matcher,
12-
parse_expect_and_typeof_vitest_fn_call, PossibleJestNode,
13-
},
10+
utils::{is_equality_matcher, parse_expect_and_typeof_vitest_fn_call, PossibleJestNode},
1411
};
1512

1613
use oxc_diagnostics::OxcDiagnostic;
@@ -104,10 +101,12 @@ declare_oxc_lint!(
104101
);
105102

106103
impl Rule for PreferToBeTruthy {
107-
fn run_once(&self, ctx: &LintContext) {
108-
for possible_vitest_node in &collect_possible_jest_call_node(ctx) {
109-
prefer_to_be_simply_bool(possible_vitest_node, ctx, true);
110-
}
104+
fn run_on_jest_node<'a, 'c>(
105+
&self,
106+
jest_node: &PossibleJestNode<'a, 'c>,
107+
ctx: &'c LintContext<'a>,
108+
) {
109+
prefer_to_be_simply_bool(jest_node, ctx, true);
111110
}
112111
}
113112

@@ -168,5 +167,8 @@ fn test() {
168167
None,
169168
),
170169
];
171-
Tester::new(PreferToBeTruthy::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
170+
Tester::new(PreferToBeTruthy::NAME, pass, fail)
171+
.expect_fix(fix)
172+
.with_vitest_plugin(true)
173+
.test_and_snapshot();
172174
}

‎crates/oxc_linter/src/rules/vitest/require_local_test_context_for_concurrent_snapshots.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use oxc_span::{GetSpan, Span};
66
use crate::{
77
context::LintContext,
88
rule::Rule,
9-
utils::{
10-
collect_possible_jest_call_node, is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind,
11-
PossibleJestNode,
12-
},
9+
utils::{is_type_of_jest_fn_call, JestFnKind, JestGeneralFnKind, PossibleJestNode},
1310
};
1411

1512
#[inline]
@@ -93,10 +90,12 @@ declare_oxc_lint!(
9390
);
9491

9592
impl Rule for RequireLocalTestContextForConcurrentSnapshots {
96-
fn run_once(&self, ctx: &LintContext) {
97-
for possible_jest_node in &collect_possible_jest_call_node(ctx) {
98-
Self::run(possible_jest_node, ctx);
99-
}
93+
fn run_on_jest_node<'a, 'c>(
94+
&self,
95+
jest_node: &PossibleJestNode<'a, 'c>,
96+
ctx: &'c LintContext<'a>,
97+
) {
98+
Self::run(jest_node, ctx);
10099
}
101100
}
102101

@@ -178,5 +177,6 @@ fn test() {
178177
];
179178

180179
Tester::new(RequireLocalTestContextForConcurrentSnapshots::NAME, pass, fail)
180+
.with_vitest_plugin(true)
181181
.test_and_snapshot();
182182
}

‎crates/oxc_linter/src/tester.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl Tester {
417417
self.current_working_directory.join(&self.rule_path)
418418
} else if let Some(path) = path {
419419
self.current_working_directory.join(path)
420-
} else if self.plugins.has_jest() {
420+
} else if self.plugins.has_test() {
421421
self.rule_path.with_extension("test.tsx")
422422
} else {
423423
self.rule_path.clone()

0 commit comments

Comments
 (0)
Please sign in to comment.