Skip to content

Commit bbafba5

Browse files
committed
docs(linter): Improve the diagnostics for jest/no-confusing-set-timeout rule. (#16815)
Minor improvements for the diagnostics used in this rule.
1 parent 9e59413 commit bbafba5

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use crate::{
1212
utils::{PossibleJestNode, collect_possible_jest_call_node, parse_jest_fn_call},
1313
};
1414

15-
fn no_global_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {
16-
OxcDiagnostic::warn("`jest.setTimeout` should be call in `global` scope").with_label(span)
15+
fn non_global_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {
16+
OxcDiagnostic::warn("`jest.setTimeout` should only be called in a global scope")
17+
.with_label(span)
1718
}
1819

1920
fn no_multiple_set_timeouts_diagnostic(span: Span) -> OxcDiagnostic {
@@ -23,7 +24,7 @@ fn no_multiple_set_timeouts_diagnostic(span: Span) -> OxcDiagnostic {
2324
}
2425

2526
fn no_unorder_set_timeout_diagnostic(span: Span) -> OxcDiagnostic {
26-
OxcDiagnostic::warn("`jest.setTimeout` should be placed before any other jest methods")
27+
OxcDiagnostic::warn("`jest.setTimeout` should be placed before any other jest methods.")
2728
.with_label(span)
2829
}
2930

@@ -178,7 +179,7 @@ fn handle_jest_set_time_out<'a>(
178179

179180
if expr.property.name == "setTimeout" {
180181
if !scopes.scope_flags(parent_node.scope_id()).is_top() {
181-
ctx.diagnostic(no_global_set_timeout_diagnostic(expr.span));
182+
ctx.diagnostic(non_global_set_timeout_diagnostic(expr.span));
182183
}
183184

184185
if *seen_jest_set_timeout {

crates/oxc_linter/src/snapshots/jest_no_confusing_set_timeout.snap

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
33
---
4-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
4+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
55
╭─[no_confusing_set_timeout.tsx:10:17]
66
9 │ });
77
10jest.setTimeout(800);
88
· ───────────────
99
11
1010
╰────
1111

12-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
12+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
1313
╭─[no_confusing_set_timeout.tsx:10:17]
1414
9 │ });
1515
10jest.setTimeout(800);
1616
· ───────────────
1717
11
1818
╰────
1919

20-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
20+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
2121
╭─[no_confusing_set_timeout.tsx:10:17]
2222
9 │ });
2323
10jest.setTimeout(800);
@@ -34,103 +34,103 @@ source: crates/oxc_linter/src/tester.rs
3434
╰────
3535
help: Only the last call to `jest.setTimeout` will have an effect.
3636

37-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
37+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
3838
╭─[no_confusing_set_timeout.tsx:10:17]
3939
9 │ });
4040
10jest.setTimeout(800);
4141
· ───────────────
4242
11
4343
╰────
4444

45-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be call in `global` scope
45+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should only be called in a global scope
4646
╭─[no_confusing_set_timeout.tsx:3:21]
4747
2describe('A', () => {
4848
3jest.setTimeout(800);
4949
· ───────────────
5050
4beforeEach(async () => { await new Promise(resolve => { setTimeout(resolve, 10000).unref(); });});
5151
╰────
5252

53-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
53+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
5454
╭─[no_confusing_set_timeout.tsx:3:21]
5555
2describe('A', () => {
5656
3jest.setTimeout(800);
5757
· ───────────────
5858
4beforeEach(async () => { await new Promise(resolve => { setTimeout(resolve, 10000).unref(); });});
5959
╰────
6060

61-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
61+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
6262
╭─[no_confusing_set_timeout.tsx:5:25]
6363
4await new Promise((resolve) => {
6464
5jest.setTimeout(1000);
6565
· ───────────────
6666
6setTimeout(resolve, 10000).unref();
6767
╰────
6868

69-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be call in `global` scope
69+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should only be called in a global scope
7070
╭─[no_confusing_set_timeout.tsx:5:25]
7171
4await new Promise((resolve) => {
7272
5jest.setTimeout(1000);
7373
· ───────────────
7474
6setTimeout(resolve, 10000).unref();
7575
╰────
7676

77-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
77+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
7878
╭─[no_confusing_set_timeout.tsx:5:25]
7979
4await new Promise((resolve) => {
8080
5jest.setTimeout(1000);
8181
· ───────────────
8282
6setTimeout(resolve, 10000).unref();
8383
╰────
8484

85-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
85+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
8686
╭─[no_confusing_set_timeout.tsx:3:21]
8787
2test('test-suite', () => {
8888
3jest.setTimeout(1000);
8989
· ───────────────
9090
4 │ });
9191
╰────
9292

93-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be call in `global` scope
93+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should only be called in a global scope
9494
╭─[no_confusing_set_timeout.tsx:3:21]
9595
2test('test-suite', () => {
9696
3jest.setTimeout(1000);
9797
· ───────────────
9898
4 │ });
9999
╰────
100100

101-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
101+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
102102
╭─[no_confusing_set_timeout.tsx:7:17]
103103
6 │ });
104104
7jest.setTimeout(1000);
105105
· ───────────────
106106
8
107107
╰────
108108

109-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
109+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
110110
╭─[no_confusing_set_timeout.tsx:7:17]
111111
6 │ });
112112
7jest.setTimeout(1000);
113113
· ───────────────
114114
8
115115
╰────
116116

117-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
117+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
118118
╭─[no_confusing_set_timeout.tsx:7:17]
119119
6 │ });
120120
7jest.setTimeout(1000);
121121
· ───────────────
122122
8
123123
╰────
124124

125-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
125+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
126126
╭─[no_confusing_set_timeout.tsx:7:17]
127127
6 │ });
128128
7jest.setTimeout(1000);
129129
· ───────────────
130130
8
131131
╰────
132132

133-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be call in `global` scope
133+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should only be called in a global scope
134134
╭─[no_confusing_set_timeout.tsx:4:20]
135135
3 │ {
136136
4jest.setTimeout(800);
@@ -147,47 +147,47 @@ source: crates/oxc_linter/src/tester.rs
147147
╰────
148148
help: Only the last call to `jest.setTimeout` will have an effect.
149149

150-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be call in `global` scope
150+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should only be called in a global scope
151151
╭─[no_confusing_set_timeout.tsx:4:21]
152152
3 │ {
153153
4Jest.setTimeout(800);
154154
· ───────────────
155155
5 │ }
156156
╰────
157157

158-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
158+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
159159
╭─[no_confusing_set_timeout.tsx:3:17]
160160
2expect(1 + 2).toEqual(3);
161161
3jest.setTimeout(1000);
162162
· ───────────────
163163
4
164164
╰────
165165

166-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
166+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
167167
╭─[no_confusing_set_timeout.tsx:8:17]
168168
7 │ });
169169
8Jest.setTimeout(800);
170170
· ───────────────
171171
9setTimeout(800);
172172
╰────
173173

174-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
174+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
175175
╭─[no_confusing_set_timeout.tsx:8:17]
176176
7 │ });
177177
8Jest.setTimeout(800);
178178
· ───────────────
179179
9setTimeout(800);
180180
╰────
181181

182-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
182+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
183183
╭─[no_confusing_set_timeout.tsx:5:21]
184184
4 │ });
185185
5jest.setTimeout(1000);
186186
· ───────────────
187187
6
188188
╰────
189189

190-
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods
190+
eslint-plugin-jest(no-confusing-set-timeout): `jest.setTimeout` should be placed before any other jest methods.
191191
╭─[no_confusing_set_timeout.tsx:5:21]
192192
4 │ });
193193
5jest.setTimeout(1000);

0 commit comments

Comments
 (0)