feat(linter): eslint-plugin-vitest/no-commented-out-tests (#4424)

This commit is contained in:
cinchen 2024-07-23 20:52:39 +08:00 committed by GitHub
parent 0e1ea90282
commit 27fdd69448
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 130 additions and 25 deletions

View file

@ -37,6 +37,17 @@ declare_oxc_lint!(
/// // it.skip('foo', () => {});
/// // test.skip('foo', () => {});
/// ```
///
/// This rule is compatible with [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-commented-out-tests.md),
/// to use it, add the following configuration to your `.eslintrc.json`:
///
/// ```json
/// {
/// "rules": {
/// "vitest/no-commented-out-tests": "error"
/// }
/// }
/// ```
NoCommentedOutTests,
suspicious
);
@ -69,7 +80,7 @@ impl Rule for NoCommentedOutTests {
fn test() {
use crate::tester::Tester;
let pass = vec![
let mut pass = vec![
("// foo('bar', function () {})", None),
("describe('foo', function () {})", None),
("it('foo', function () {})", None),
@ -120,7 +131,7 @@ fn test() {
),
];
let fail = vec![
let mut fail = vec![
("// fdescribe('foo', function () {})", None),
("// describe['skip']('foo', function () {})", None),
("// describe['skip']('foo', function () {})", None),
@ -170,5 +181,46 @@ fn test() {
),
];
Tester::new(NoCommentedOutTests::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
let pass_vitest = vec![
r#"// foo("bar", function () {})"#,
r#"describe("foo", function () {})"#,
r#"it("foo", function () {})"#,
r#"describe.only("foo", function () {})"#,
r#"it.only("foo", function () {})"#,
r#"it.concurrent("foo", function () {})"#,
r#"test("foo", function () {})"#,
r#"test.only("foo", function () {})"#,
r#"test.concurrent("foo", function () {})"#,
r"var appliedSkip = describe.skip; appliedSkip.apply(describe)",
r"var calledSkip = it.skip; calledSkip.call(it)",
r"({ f: function () {} }).f()",
r"(a || b).f()",
r"itHappensToStartWithIt()",
r"testSomething()",
r"// latest(dates)",
r"// TODO: unify with Git implementation from Shipit (?)",
"#!/usr/bin/env node#",
];
let fail_vitest = vec![
r"// describe(\'foo\', function () {})\'",
r#"// test.concurrent("foo", function () {})"#,
r#"// test["skip"]("foo", function () {})"#,
r#"// xdescribe("foo", function () {})"#,
r#"// xit("foo", function () {})"#,
r#"// fit("foo", function () {})"#,
r#"
// test(
// "foo", function () {}
// )
"#,
];
pass.extend(pass_vitest.into_iter().map(|x| (x, None)));
fail.extend(fail_vitest.into_iter().map(|x| (x, None)));
Tester::new(NoCommentedOutTests::NAME, pass, fail)
.with_jest_plugin(true)
.with_vitest_plugin(true)
.test_and_snapshot();
}

View file

@ -1,105 +1,106 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 216
---
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // fdescribe('foo', function () {})
· ─────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // describe['skip']('foo', function () {})
· ────────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // describe['skip']('foo', function () {})
· ────────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // it.skip('foo', function () {})
· ───────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // it.only('foo', function () {})
· ───────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // it.concurrent('foo', function () {})
· ─────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // it['skip']('foo', function () {})
· ──────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test.skip('foo', function () {})
· ─────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test.concurrent('foo', function () {})
· ───────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test['skip']('foo', function () {})
· ────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // xdescribe('foo', function () {})
· ─────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // xit('foo', function () {})
· ───────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // fit('foo', function () {})
· ───────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // xtest('foo', function () {})
· ─────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:2:17]
1 │
2 │ // test(
@ -108,7 +109,7 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:2:17]
1 │
2 │ ╭─▶ /* test
@ -120,42 +121,42 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // it('has title but no callback')
· ────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // it()
· ─────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test.someNewMethodThatMightBeAddedInTheFuture()
· ────────────────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test['someNewMethodThatMightBeAddedInTheFuture']()
· ───────────────────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test('has title but no callback')
· ──────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-jest(no-commented-out-tests): Some tests seem to be commented
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:3:17]
2 │ foo()
3 │ ╭─▶ /*
@ -164,3 +165,54 @@ source: crates/oxc_linter/src/tester.rs
6 │ bar()
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // describe(\'foo\', function () {})\'
· ────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test.concurrent("foo", function () {})
· ───────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // test["skip"]("foo", function () {})
· ────────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // xdescribe("foo", function () {})
· ─────────────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // xit("foo", function () {})
· ───────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:1:3]
1 │ // fit("foo", function () {})
· ───────────────────────────
╰────
help: Remove or uncomment this comment
⚠ eslint-plugin-vitest(no-commented-out-tests): Some tests seem to be commented
╭─[no_commented_out_tests.tsx:2:15]
1 │
2 │ // test(
· ──────
3 │ // "foo", function () {}
╰────
help: Remove or uncomment this comment

View file

@ -18,6 +18,7 @@ pub fn is_jest_rule_adapted_to_vitest(rule_name: &str) -> bool {
"consistent-test-it",
"expect-expect",
"no-alias-methods",
"no-commented-out-tests",
"no-disabled-tests",
"no-focused-tests",
"no-test-prefixes",