diff --git a/crates/oxc_linter/src/rules/jest/valid_expect.rs b/crates/oxc_linter/src/rules/jest/valid_expect.rs index 711a6e7cab513..be2923a731d75 100644 --- a/crates/oxc_linter/src/rules/jest/valid_expect.rs +++ b/crates/oxc_linter/src/rules/jest/valid_expect.rs @@ -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)); diff --git a/crates/oxc_linter/src/snapshots/valid_expect.snap b/crates/oxc_linter/src/snapshots/valid_expect.snap index 4e2f9791f5727..7ac7d89bc3f1c 100644 --- a/crates/oxc_linter/src/snapshots/valid_expect.snap +++ b/crates/oxc_linter/src/snapshots/valid_expect.snap @@ -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'); · ─────────────────────────── @@ -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"); · ───────────────────────────