diff --git a/Cargo.lock b/Cargo.lock index a0122e94c9516..02c78f8800b1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -905,12 +905,9 @@ dependencies = [ [[package]] name = "json-strip-comments" -version = "1.0.4" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b271732a960335e715b6b2ae66a086f115c74eb97360e996d2bd809bfc063bba" -dependencies = [ - "memchr", -] +checksum = "c3d129799327c8f80861e467c59b825ba24c277dba6ad0d71a141dc98f9e04ee" [[package]] name = "language-tags" @@ -1691,9 +1688,9 @@ dependencies = [ [[package]] name = "oxc_resolver" -version = "1.10.2" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5f862ee8e1ba728378ac7e007de195ae00fbb21337ef152380c052cc07e2ee2" +checksum = "c368aa1e41d8f8fb0ecbbe7130cd47814897f9a537cc7213be586ec34702d31f" dependencies = [ "dashmap 6.0.1", "dunce", @@ -2488,9 +2485,9 @@ dependencies = [ [[package]] name = "similar" -version = "2.6.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" [[package]] name = "siphasher" @@ -2672,9 +2669,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.1" +version = "1.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", "bytes", diff --git a/crates/oxc_linter/src/rules/jest/no_identical_title.rs b/crates/oxc_linter/src/rules/jest/no_identical_title.rs index be024a22b4bad..600a2f45cc39f 100644 --- a/crates/oxc_linter/src/rules/jest/no_identical_title.rs +++ b/crates/oxc_linter/src/rules/jest/no_identical_title.rs @@ -56,6 +56,17 @@ declare_oxc_lint!( /// // ... /// }); /// ``` + /// + /// This rule is compatible with [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-identical-title.md), + /// to use it, add the following configuration to your `.eslintrc.json`: + /// + /// ```json + /// { + /// "rules": { + /// "vitest/no-identical-title": "error" + /// } + /// } + /// ``` NoIdenticalTitle, style ); @@ -159,7 +170,7 @@ fn get_closest_block(node: &AstNode, ctx: &LintContext) -> Option { fn test() { use crate::tester::Tester; - let pass = vec![ + let mut pass = vec![ ("it(); it();", None), ("describe(); describe();", None), ("describe('foo', () => {}); it('foo', () => {});", None), @@ -361,7 +372,7 @@ fn test() { ), ]; - let fail = vec![ + let mut fail = vec![ ( " describe('foo', () => { @@ -463,5 +474,63 @@ fn test() { // ), ]; - Tester::new(NoIdenticalTitle::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot(); + let pass_vitest = vec![ + " + suite('parent', () => { + suite('child 1', () => { + test('grand child 1', () => {}) + }) + suite('child 2', () => { + test('grand child 1', () => {}) + }) + }) + ", + "it(); it();", + r#"test("two", () => {});"#, + " + fdescribe('a describe', () => { + test('a test', () => { + expect(true).toBe(true); + }); + }); + fdescribe('another describe', () => { + test('a test', () => { + expect(true).toBe(true); + }); + }); + ", + " + suite('parent', () => { + suite('child 1', () => { + test('grand child 1', () => {}) + }) + suite('child 2', () => { + test('grand child 1', () => {}) + }) + }) + ", + ]; + + let fail_vitest = vec![ + " + describe('foo', () => { + it('works', () => {}); + it('works', () => {}); + }); + ", + " + xdescribe('foo', () => { + it('works', () => {}); + it('works', () => {}); + }); + ", + ]; + + pass.extend(pass_vitest.into_iter().map(|x| (x, None))); + fail.extend(fail_vitest.into_iter().map(|x| (x, None))); + + Tester::new(NoIdenticalTitle::NAME, pass, fail) + .with_jest_plugin(true) + .with_vitest_plugin(true) + .test_and_snapshot(); } diff --git a/crates/oxc_linter/src/snapshots/no_identical_title.snap b/crates/oxc_linter/src/snapshots/no_identical_title.snap index dfecaa59127ac..7eee47d058713 100644 --- a/crates/oxc_linter/src/snapshots/no_identical_title.snap +++ b/crates/oxc_linter/src/snapshots/no_identical_title.snap @@ -1,7 +1,8 @@ --- source: crates/oxc_linter/src/tester.rs +assertion_line: 216 --- - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:4:20] 3 │ it('works', () => {}); 4 │ it('works', () => {}); @@ -10,7 +11,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:18] 2 │ it('works', () => {}); 3 │ it('works', () => {}); @@ -19,7 +20,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:20] 2 │ test.only('this', () => {}); 3 │ test('this', () => {}); @@ -28,7 +29,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:2:21] 1 │ 2 │ xtest('this', () => {}); @@ -37,7 +38,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:25] 2 │ test.only('this', () => {}); 3 │ test.only('this', () => {}); @@ -46,7 +47,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:31] 2 │ test.concurrent('this', () => {}); 3 │ test.concurrent('this', () => {}); @@ -55,7 +56,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:31] 2 │ test.only('this', () => {}); 3 │ test.concurrent('this', () => {}); @@ -64,7 +65,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of test. - ⚠ eslint-plugin-jest(no-identical-title): Describe block title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Describe block title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:24] 2 │ describe('foo', () => {}); 3 │ describe('foo', () => {}); @@ -73,7 +74,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of describe block. - ⚠ eslint-plugin-jest(no-identical-title): Describe block title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Describe block title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:2:24] 1 │ 2 │ describe('foo', () => {}); @@ -82,7 +83,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of describe block. - ⚠ eslint-plugin-jest(no-identical-title): Describe block title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Describe block title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:3:24] 2 │ fdescribe('foo', () => {}); 3 │ describe('foo', () => {}); @@ -91,7 +92,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of describe block. - ⚠ eslint-plugin-jest(no-identical-title): Describe block title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Describe block title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:5:24] 4 │ }); 5 │ describe('foo', () => {}); @@ -100,7 +101,7 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Change the title of describe block. - ⚠ eslint-plugin-jest(no-identical-title): Test title is used multiple times in the same describe block. + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. ╭─[no_identical_title.tsx:4:20] 3 │ it(`catches backticks with the same title`, () => {}); 4 │ it(`catches backticks with the same title`, () => {}); @@ -108,3 +109,21 @@ source: crates/oxc_linter/src/tester.rs 5 │ }); ╰──── help: Change the title of test. + + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. + ╭─[no_identical_title.tsx:4:20] + 3 │ it('works', () => {}); + 4 │ it('works', () => {}); + · ─────── + 5 │ }); + ╰──── + help: Change the title of test. + + ⚠ eslint-plugin-vitest(no-identical-title): Test title is used multiple times in the same describe block. + ╭─[no_identical_title.tsx:4:20] + 3 │ it('works', () => {}); + 4 │ it('works', () => {}); + · ─────── + 5 │ }); + ╰──── + help: Change the title of test. diff --git a/crates/oxc_linter/src/utils/mod.rs b/crates/oxc_linter/src/utils/mod.rs index 75efafd061a42..924567436eb44 100644 --- a/crates/oxc_linter/src/utils/mod.rs +++ b/crates/oxc_linter/src/utils/mod.rs @@ -22,6 +22,7 @@ pub fn is_jest_rule_adapted_to_vitest(rule_name: &str) -> bool { "no-commented-out-tests", "no-disabled-tests", "no-focused-tests", + "no-identical-title", "no-test-prefixes", "prefer-hooks-in-order", "valid-describe-callback",