diff --git a/crates/oxc_linter/src/rules.rs b/crates/oxc_linter/src/rules.rs index fc7e7383b400d..3c8eacefa5ea0 100644 --- a/crates/oxc_linter/src/rules.rs +++ b/crates/oxc_linter/src/rules.rs @@ -236,6 +236,7 @@ mod jest { pub mod no_untyped_mock_factory; pub mod prefer_called_with; pub mod prefer_comparison_matcher; + pub mod prefer_each; pub mod prefer_equality_matcher; pub mod prefer_expect_resolves; pub mod prefer_hooks_in_order; @@ -515,7 +516,6 @@ mod promise { mod vitest { pub mod no_conditional_tests; pub mod no_import_node_test; - pub mod prefer_each; pub mod prefer_to_be_falsy; pub mod prefer_to_be_object; pub mod prefer_to_be_truthy; @@ -704,6 +704,7 @@ oxc_macros::declare_all_lint_rules! { jest::no_test_prefixes, jest::no_test_return_statement, jest::no_untyped_mock_factory, + jest::prefer_each, jest::prefer_called_with, jest::prefer_comparison_matcher, jest::prefer_equality_matcher, @@ -1000,7 +1001,6 @@ oxc_macros::declare_all_lint_rules! { unicorn::throw_new_error, vitest::no_conditional_tests, vitest::no_import_node_test, - vitest::prefer_each, vitest::prefer_to_be_falsy, vitest::prefer_to_be_object, vitest::prefer_to_be_truthy, diff --git a/crates/oxc_linter/src/rules/vitest/prefer_each.rs b/crates/oxc_linter/src/rules/jest/prefer_each.rs similarity index 67% rename from crates/oxc_linter/src/rules/vitest/prefer_each.rs rename to crates/oxc_linter/src/rules/jest/prefer_each.rs index 5d013374ae86d..cd928ed521c42 100644 --- a/crates/oxc_linter/src/rules/vitest/prefer_each.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_each.rs @@ -64,7 +64,7 @@ declare_oxc_lint!( /// }) /// ``` PreferEach, - vitest, + jest, style, ); @@ -147,7 +147,140 @@ impl PreferEach { fn test() { use crate::tester::Tester; - let pass = vec![ + let pass_jest = vec![ + r#"it("is true", () => { expect(true).toBe(false) });"#, + r#"it.each(getNumbers())("only returns numbers that are greater than seven", number => { + expect(number).toBeGreaterThan(7); + });"#, + r#"it("returns numbers that are greater than five", function () { + for (const number of getNumbers()) { + expect(number).toBeGreaterThan(5); + } + });"#, + r#"it("returns things that are less than ten", function () { + for (const thing in things) { + expect(thing).toBeLessThan(10); + } + });"#, + r#"it("only returns numbers that are greater than seven", function () { + const numbers = getNumbers(); + for (let i = 0; i < numbers.length; i++) { + expect(numbers[i]).toBeGreaterThan(7); + } + });"#, + ]; + + let fail_jest = vec![ + "for (const [input, expected] of data) { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "for (const [input, expected] of data) { + describe(\\`when the input is $\\{input}\\`, () => { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }); + }", + "for (const [input, expected] of data) { + describe(\\`when the input is $\\{input}\\`, () => { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }); + } + for (const [input, expected] of data) { + it.skip(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "for (const [input, expected] of data) { + it.skip(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "it('is true', () => { + expect(true).toBe(false); + }); + for (const [input, expected] of data) { + it.skip(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "for (const [input, expected] of data) { + it.skip(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + } + it('is true', () => { + expect(true).toBe(false); + });", + "it('is true', () => { + expect(true).toBe(false); + }); + for (const [input, expected] of data) { + it.skip(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + } + it('is true', () => { + expect(true).toBe(false); + });", + "for (const [input, expected] of data) { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "for (const [input, expected] of data) { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + } + for (const [input, expected] of data) { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "for (const [input, expected] of data) { + it(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + } + for (const [input, expected] of data) { + test(\\`results in $\\{expected}\\`, () => { + expect(fn(input)).toBe(expected) + }); + }", + "for (const [input, expected] of data) { + beforeEach(() => setupSomething(input)); + test(\\`results in $\\{expected}\\`, () => { + expect(doSomething()).toBe(expected) + }); + }", + r#"for (const [input, expected] of data) { + it("only returns numbers that are greater than seven", function () { + const numbers = getNumbers(input); + for (let i = 0; i < numbers.length; i++) { + expect(numbers[i]).toBeGreaterThan(7); + } + }); + }"#, + r#"for (const [input, expected] of data) { + beforeEach(() => setupSomething(input)); + it("only returns numbers that are greater than seven", function () { + const numbers = getNumbers(); + for (let i = 0; i < numbers.length; i++) { + expect(numbers[i]).toBeGreaterThan(7); + } + }); + }"#, + ]; + + let pass_vitest = vec![ r#"it("is true", () => { expect(true).toBe(false) });"#, r#"it.each(getNumbers())("only returns numbers that are greater than seven", number => { expect(number).toBeGreaterThan(7); @@ -171,7 +304,7 @@ fn test() { });"#, ]; - let fail = vec![ + let fail_vitest = vec![ " for (const [input, expected] of data) { it(`results in ${expected}`, () => { expect(fn(input)).toBe(expected) @@ -286,5 +419,12 @@ fn test() { "#, ]; + let mut pass = vec![]; + pass.extend(pass_jest); + pass.extend(pass_vitest); + let mut fail = vec![]; + fail.extend(fail_jest); + fail.extend(fail_vitest); + Tester::new(PreferEach::NAME, PreferEach::PLUGIN, pass, fail).test_and_snapshot(); } diff --git a/crates/oxc_linter/src/snapshots/jest_prefer_each.snap b/crates/oxc_linter/src/snapshots/jest_prefer_each.snap new file mode 100644 index 0000000000000..1bf6f93a4b7d6 --- /dev/null +++ b/crates/oxc_linter/src/snapshots/jest_prefer_each.snap @@ -0,0 +1,396 @@ +--- +source: crates/oxc_linter/src/tester.rs +snapshot_kind: text +--- + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:10] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:24] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:2:33] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:16] + 1 │ for (const [input, expected] of data) { + 2 │ describe(\`when the input is $\{input}\`, () => { + · ─ + 3 │ it(\`results in $\{expected}\`, () => { + ╰──── + + × Expected `,` but found `Identifier` + ╭─[prefer_each.tsx:2:22] + 1 │ for (const [input, expected] of data) { + 2 │ describe(\`when the input is $\{input}\`, () => { + · ─┬─ + · ╰── `,` expected + 3 │ it(\`results in $\{expected}\`, () => { + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:16] + 1 │ for (const [input, expected] of data) { + 2 │ describe(\`when the input is $\{input}\`, () => { + · ─ + 3 │ it(\`results in $\{expected}\`, () => { + ╰──── + + × Expected `,` but found `Identifier` + ╭─[prefer_each.tsx:2:22] + 1 │ for (const [input, expected] of data) { + 2 │ describe(\`when the input is $\{input}\`, () => { + · ─┬─ + · ╰── `,` expected + 3 │ it(\`results in $\{expected}\`, () => { + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:15] + 1 │ for (const [input, expected] of data) { + 2 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:29] + 1 │ for (const [input, expected] of data) { + 2 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:2:38] + 1 │ for (const [input, expected] of data) { + 2 │ it.skip(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:5:15] + 4 │ for (const [input, expected] of data) { + 5 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 6 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:5:29] + 4 │ for (const [input, expected] of data) { + 5 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 6 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:5:38] + 4 │ for (const [input, expected] of data) { + 5 │ it.skip(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 6 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:15] + 1 │ for (const [input, expected] of data) { + 2 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:29] + 1 │ for (const [input, expected] of data) { + 2 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:2:38] + 1 │ for (const [input, expected] of data) { + 2 │ it.skip(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:5:15] + 4 │ for (const [input, expected] of data) { + 5 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 6 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:5:29] + 4 │ for (const [input, expected] of data) { + 5 │ it.skip(\`results in $\{expected}\`, () => { + · ─ + 6 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:5:38] + 4 │ for (const [input, expected] of data) { + 5 │ it.skip(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 6 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:10] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:24] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:2:33] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:10] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:24] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:2:33] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:10] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:2:24] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ─ + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:2:33] + 1 │ for (const [input, expected] of data) { + 2 │ it(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 3 │ expect(fn(input)).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:3:12] + 2 │ beforeEach(() => setupSomething(input)); + 3 │ test(\`results in $\{expected}\`, () => { + · ─ + 4 │ expect(doSomething()).toBe(expected) + ╰──── + + × Invalid Unicode escape sequence + ╭─[prefer_each.tsx:3:26] + 2 │ beforeEach(() => setupSomething(input)); + 3 │ test(\`results in $\{expected}\`, () => { + · ─ + 4 │ expect(doSomething()).toBe(expected) + ╰──── + + × Expected `,` but found `}` + ╭─[prefer_each.tsx:3:35] + 2 │ beforeEach(() => setupSomething(input)); + 3 │ test(\`results in $\{expected}\`, () => { + · ┬ + · ╰── `,` expected + 4 │ expect(doSomething()).toBe(expected) + ╰──── + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ it("only returns numbers that are greater than seven", function () { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ beforeEach(() => setupSomething(input)); + ╰──── + help: Prefer using `describe.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:3] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ it(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:2] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ describe(`when the input is ${input}`, () => { + ╰──── + help: Prefer using `describe.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ describe(`when the input is ${input}`, () => { + ╰──── + help: Prefer using `describe.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:9:11] + 8 │ + 9 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 10 │ it.skip(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ it.skip(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:5:11] + 4 │ + 5 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 6 │ it.skip(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:2] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ it.skip(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:5:11] + 4 │ + 5 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 6 │ it.skip(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ it(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ it(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:7:11] + 6 │ + 7 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 8 │ it(`results in ${expected}`, () => { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:1:1] + 1 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 2 │ beforeEach(() => setupSomething(input)); + ╰──── + help: Prefer using `describe.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:2:11] + 1 │ + 2 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 3 │ it("only returns numbers that are greater than seven", function () { + ╰──── + help: Prefer using `it.each` rather than a manual loop. + + ⚠ eslint-plugin-jest(prefer-each): Enforce using `each` rather than manual loops + ╭─[prefer_each.tsx:2:11] + 1 │ + 2 │ for (const [input, expected] of data) { + · ────────────────────────────────────── + 3 │ beforeEach(() => setupSomething(input)); + ╰──── + help: Prefer using `describe.each` rather than a manual loop. diff --git a/crates/oxc_linter/src/snapshots/vitest_prefer_each.snap b/crates/oxc_linter/src/snapshots/vitest_prefer_each.snap deleted file mode 100644 index f9cbcf1fff6fc..0000000000000 --- a/crates/oxc_linter/src/snapshots/vitest_prefer_each.snap +++ /dev/null @@ -1,121 +0,0 @@ ---- -source: crates/oxc_linter/src/tester.rs -snapshot_kind: text ---- - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:3] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ it(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:2] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ describe(`when the input is ${input}`, () => { - ╰──── - help: Prefer using `describe.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:1] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ describe(`when the input is ${input}`, () => { - ╰──── - help: Prefer using `describe.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:9:11] - 8 │ - 9 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 10 │ it.skip(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:1] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ it.skip(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:5:11] - 4 │ - 5 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 6 │ it.skip(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:2] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ it.skip(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:5:11] - 4 │ - 5 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 6 │ it.skip(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:1] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ it(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:1] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ it(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:7:11] - 6 │ - 7 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 8 │ it(`results in ${expected}`, () => { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:1:1] - 1 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 2 │ beforeEach(() => setupSomething(input)); - ╰──── - help: Prefer using `describe.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:2:11] - 1 │ - 2 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 3 │ it("only returns numbers that are greater than seven", function () { - ╰──── - help: Prefer using `it.each` rather than a manual loop. - - ⚠ eslint-plugin-vitest(prefer-each): Enforce using `each` rather than manual loops - ╭─[prefer_each.tsx:2:11] - 1 │ - 2 │ for (const [input, expected] of data) { - · ────────────────────────────────────── - 3 │ beforeEach(() => setupSomething(input)); - ╰──── - help: Prefer using `describe.each` rather than a manual loop. diff --git a/crates/oxc_linter/src/utils/mod.rs b/crates/oxc_linter/src/utils/mod.rs index c3627fb7d6cd8..457338cee643c 100644 --- a/crates/oxc_linter/src/utils/mod.rs +++ b/crates/oxc_linter/src/utils/mod.rs @@ -29,6 +29,7 @@ const VITEST_COMPATIBLE_JEST_RULES: phf::Set<&'static str> = phf::phf_set! { "no-identical-title", "no-restricted-jest-methods", "no-test-prefixes", + "prefer-each", "prefer-hooks-in-order", "valid-describe-callback", "valid-expect",