Skip to content

Commit

Permalink
fix(linter): error diagnostic message based on parameter length of va…
Browse files Browse the repository at this point in the history
…lid-expect (#6455)
  • Loading branch information
shulaoda authored Oct 11, 2024
1 parent 073b02a commit e811812
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/rules/jest/valid_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,21 @@ impl ValidExpect {
return;
};

if call_expr.arguments.len() < self.min_args {
if call_expr.arguments.len() > self.max_args {
let error = format!(
"Expect takes at most {} argument{} ",
self.min_args,
if self.min_args > 1 { "s" } else { "" }
self.max_args,
if self.max_args > 1 { "s" } else { "" }
);
let help = "Remove the extra arguments.";
ctx.diagnostic(valid_expect_diagnostic(error, help, call_expr.span));
return;
}
if call_expr.arguments.len() > self.max_args {
if call_expr.arguments.len() < self.min_args {
let error = format!(
"Expect requires at least {} argument{} ",
self.max_args,
if self.max_args > 1 { "s" } else { "" }
self.min_args,
if self.min_args > 1 { "s" } else { "" }
);
let help = "Add the missing arguments.";
ctx.diagnostic(valid_expect_diagnostic(error, help, call_expr.span));
Expand Down
68 changes: 34 additions & 34 deletions crates/oxc_linter/src/snapshots/valid_expect.snap
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
---
source: crates/oxc_linter/src/tester.rs
---
eslint-plugin-vitest(valid-expect): Expect takes at most 1 argument
eslint-plugin-vitest(valid-expect): Expect requires at least 1 argument
╭─[valid_expect.tsx:1:1]
1expect().toBe(2);
· ────────
╰────
help: Remove the extra arguments.
help: Add the missing arguments.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit e811812

Please sign in to comment.