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

feat(linter): eslint-plugin-vitest/no-identical-title #4422

Merged
merged 7 commits into from
Jul 25, 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
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]
3 │ it('works', () => {});
4 │ it('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]
2 │ it('works', () => {});
3 │ it('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]
2 │ test.only('this', () => {});
3 │ test('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 │
2 │ xtest('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]
2 │ test.only('this', () => {});
3 │ test.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]
2 │ test.concurrent('this', () => {});
3 │ test.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]
2 │ test.only('this', () => {});
3 │ test.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]
2 │ describe('foo', () => {});
3 │ describe('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 │
2 │ describe('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]
2 │ fdescribe('foo', () => {});
3 │ describe('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 │ });
5 │ describe('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]
3 │ it(`catches backticks with the same title`, () => {});
4 │ it(`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]
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.
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
Loading