Skip to content

Commit e811812

Browse files
authored
fix(linter): error diagnostic message based on parameter length of valid-expect (#6455)
1 parent 073b02a commit e811812

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ impl ValidExpect {
159159
return;
160160
};
161161

162-
if call_expr.arguments.len() < self.min_args {
162+
if call_expr.arguments.len() > self.max_args {
163163
let error = format!(
164164
"Expect takes at most {} argument{} ",
165-
self.min_args,
166-
if self.min_args > 1 { "s" } else { "" }
165+
self.max_args,
166+
if self.max_args > 1 { "s" } else { "" }
167167
);
168168
let help = "Remove the extra arguments.";
169169
ctx.diagnostic(valid_expect_diagnostic(error, help, call_expr.span));
170170
return;
171171
}
172-
if call_expr.arguments.len() > self.max_args {
172+
if call_expr.arguments.len() < self.min_args {
173173
let error = format!(
174174
"Expect requires at least {} argument{} ",
175-
self.max_args,
176-
if self.max_args > 1 { "s" } else { "" }
175+
self.min_args,
176+
if self.min_args > 1 { "s" } else { "" }
177177
);
178178
let help = "Add the missing arguments.";
179179
ctx.diagnostic(valid_expect_diagnostic(error, help, call_expr.span));

crates/oxc_linter/src/snapshots/valid_expect.snap

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
33
---
4-
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
4+
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
55
╭─[valid_expect.tsx:1:1]
66
1expect().toBe(2);
77
· ────────
88
╰────
9-
help: Remove the extra arguments.
9+
help: Add the missing arguments.
1010

11-
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
11+
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
1212
╭─[valid_expect.tsx:1:1]
1313
1expect().toBe(true);
1414
· ────────
1515
╰────
16-
help: Remove the extra arguments.
16+
help: Add the missing arguments.
1717

18-
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
18+
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
1919
╭─[valid_expect.tsx:1:1]
2020
1expect().toEqual('something');
2121
· ────────
2222
╰────
23-
help: Remove the extra arguments.
23+
help: Add the missing arguments.
2424

25-
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
25+
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
2626
╭─[valid_expect.tsx:1:1]
2727
1expect('something', 'else').toEqual('something');
2828
· ───────────────────────────
2929
╰────
30-
help: Add the missing arguments.
30+
help: Remove the extra arguments.
3131

32-
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
32+
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
3333
╭─[valid_expect.tsx:1:1]
3434
1expect('something', 'else', 'entirely').toEqual('something');
3535
· ───────────────────────────────────────
3636
╰────
37-
help: Add the missing arguments.
37+
help: Remove the extra arguments.
3838

39-
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
39+
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
4040
╭─[valid_expect.tsx:1:1]
4141
1expect('something', 'else', 'entirely').toEqual('something');
4242
· ───────────────────────────────────────
4343
╰────
44-
help: Add the missing arguments.
44+
help: Remove the extra arguments.
4545

46-
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
46+
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
4747
╭─[valid_expect.tsx:1:1]
4848
1expect('something', 'else', 'entirely').toEqual('something');
4949
· ───────────────────────────────────────
5050
╰────
51-
help: Add the missing arguments.
51+
help: Remove the extra arguments.
5252

53-
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
53+
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
5454
╭─[valid_expect.tsx:1:1]
5555
1expect('something').toEqual('something');
5656
· ───────────────────
5757
╰────
58-
help: Remove the extra arguments.
58+
help: Add the missing arguments.
5959

60-
eslint-plugin-vitest(valid-expect): Expect takes at most 3 arguments
60+
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
6161
╭─[valid_expect.tsx:1:1]
6262
1expect('something', 'else').toEqual('something');
6363
· ───────────────────────────
@@ -498,63 +498,63 @@ source: crates/oxc_linter/src/tester.rs
498498
╰────
499499
help: Did you forget add a matcher(e.g. `toBe`, `toBeDefined`)
500500

501-
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
501+
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
502502
╭─[valid_expect.tsx:1:1]
503503
1expect().toBe(2);
504504
· ────────
505505
╰────
506-
help: Remove the extra arguments.
506+
help: Add the missing arguments.
507507

508-
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
508+
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
509509
╭─[valid_expect.tsx:1:1]
510510
1expect().toBe(true);
511511
· ────────
512512
╰────
513-
help: Remove the extra arguments.
513+
help: Add the missing arguments.
514514

515-
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
515+
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
516516
╭─[valid_expect.tsx:1:1]
517517
1expect().toEqual("something");
518518
· ────────
519519
╰────
520-
help: Remove the extra arguments.
520+
help: Add the missing arguments.
521521

522-
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
522+
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
523523
╭─[valid_expect.tsx:1:1]
524524
1expect("something", "else").toEqual("something");
525525
· ───────────────────────────
526526
╰────
527-
help: Add the missing arguments.
527+
help: Remove the extra arguments.
528528

529-
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
529+
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
530530
╭─[valid_expect.tsx:1:1]
531531
1expect("something", "else", "entirely").toEqual("something");
532532
· ───────────────────────────────────────
533533
╰────
534-
help: Add the missing arguments.
534+
help: Remove the extra arguments.
535535

536-
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
536+
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
537537
╭─[valid_expect.tsx:1:1]
538538
1expect("something", "else", "entirely").toEqual("something");
539539
· ───────────────────────────────────────
540540
╰────
541-
help: Add the missing arguments.
541+
help: Remove the extra arguments.
542542

543-
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
543+
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
544544
╭─[valid_expect.tsx:1:1]
545545
1expect("something", "else", "entirely").toEqual("something");
546546
· ───────────────────────────────────────
547547
╰────
548-
help: Add the missing arguments.
548+
help: Remove the extra arguments.
549549

550-
eslint-plugin-vitest(valid-expect): Expect takes at most 2 arguments
550+
eslint-plugin-vitest(valid-expect): Expect requires at least 2 arguments
551551
╭─[valid_expect.tsx:1:1]
552552
1expect("something").toEqual("something");
553553
· ───────────────────
554554
╰────
555-
help: Remove the extra arguments.
555+
help: Add the missing arguments.
556556

557-
eslint-plugin-vitest(valid-expect): Expect takes at most 3 arguments
557+
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
558558
╭─[valid_expect.tsx:1:1]
559559
1expect("something", "else").toEqual("something");
560560
· ───────────────────────────

0 commit comments

Comments
 (0)