Skip to content

Commit

Permalink
feat(linter): eslint-plugin-vitest/no-identical-title (#4422)
Browse files Browse the repository at this point in the history
support
[eslint-plugin-vitest/no-identical-title](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-identical-title.md)

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
  • Loading branch information
eryue0220 and DonIsaac authored Jul 25, 2024
1 parent 855f2f6 commit e3b0c40
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 26 deletions.
19 changes: 8 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 72 additions & 3 deletions crates/oxc_linter/src/rules/jest/no_identical_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -159,7 +170,7 @@ fn get_closest_block(node: &AstNode, ctx: &LintContext) -> Option<AstNodeId> {
fn test() {
use crate::tester::Tester;

let pass = vec![
let mut pass = vec![
("it(); it();", None),
("describe(); describe();", None),
("describe('foo', () => {}); it('foo', () => {});", None),
Expand Down Expand Up @@ -361,7 +372,7 @@ fn test() {
),
];

let fail = vec![
let mut fail = vec![
(
"
describe('foo', () => {
Expand Down Expand Up @@ -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();
}
43 changes: 31 additions & 12 deletions crates/oxc_linter/src/snapshots/no_identical_title.snap
Original file line number Diff line number Diff line change
@@ -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]
3it('works', () => {});
4it('works', () => {});
Expand All @@ -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]
2it('works', () => {});
3it('works', () => {});
Expand All @@ -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]
2test.only('this', () => {});
3test('this', () => {});
Expand All @@ -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
2xtest('this', () => {});
Expand All @@ -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]
2test.only('this', () => {});
3test.only('this', () => {});
Expand All @@ -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]
2test.concurrent('this', () => {});
3test.concurrent('this', () => {});
Expand All @@ -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]
2test.only('this', () => {});
3test.concurrent('this', () => {});
Expand All @@ -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]
2describe('foo', () => {});
3describe('foo', () => {});
Expand All @@ -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
2describe('foo', () => {});
Expand All @@ -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]
2fdescribe('foo', () => {});
3describe('foo', () => {});
Expand All @@ -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 │ });
5describe('foo', () => {});
Expand All @@ -100,11 +101,29 @@ 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]
3it(`catches backticks with the same title`, () => {});
4it(`catches backticks with the same title`, () => {});
· ───────────────────────────────────────
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]
3it('works', () => {});
4it('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]
3it('works', () => {});
4it('works', () => {});
· ───────
5 │ });
╰────
help: Change the title of test.
1 change: 1 addition & 0 deletions crates/oxc_linter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e3b0c40

Please sign in to comment.