diff --git a/crates/oxc_linter/src/rules/jest/no_commented_out_tests.rs b/crates/oxc_linter/src/rules/jest/no_commented_out_tests.rs index 4df3cd5ee323b..90c495c6f46c4 100644 --- a/crates/oxc_linter/src/rules/jest/no_commented_out_tests.rs +++ b/crates/oxc_linter/src/rules/jest/no_commented_out_tests.rs @@ -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(); } diff --git a/crates/oxc_linter/src/snapshots/no_commented_out_tests.snap b/crates/oxc_linter/src/snapshots/no_commented_out_tests.snap index dd899762988cd..e4a865272a65e 100644 --- a/crates/oxc_linter/src/snapshots/no_commented_out_tests.snap +++ b/crates/oxc_linter/src/snapshots/no_commented_out_tests.snap @@ -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 diff --git a/crates/oxc_linter/src/utils/mod.rs b/crates/oxc_linter/src/utils/mod.rs index b785151ee95fb..149008b7e6fdd 100644 --- a/crates/oxc_linter/src/utils/mod.rs +++ b/crates/oxc_linter/src/utils/mod.rs @@ -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",