Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): error diagnostic message based on parameter length of valid-expect #6455

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
1 │ expect().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]
1 │ expect().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]
1 │ expect().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]
1 │ expect('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]
1 │ expect('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]
1 │ expect('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]
1 │ expect('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]
1 │ expect('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]
1 │ expect('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]
1 │ expect().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]
1 │ expect().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]
1 │ expect().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]
1 │ expect("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]
1 │ expect("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]
1 │ expect("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]
1 │ expect("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]
1 │ expect("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]
1 │ expect("something", "else").toEqual("something");
· ───────────────────────────
Expand Down