Skip to content

Commit

Permalink
feat(linter): eslint-plugin-vitest/no-commented-out-tests (#4424)
Browse files Browse the repository at this point in the history
  • Loading branch information
eryue0220 authored Jul 23, 2024
1 parent 0e1ea90 commit 27fdd69
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 25 deletions.
58 changes: 55 additions & 3 deletions crates/oxc_linter/src/rules/jest/no_commented_out_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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();
}
96 changes: 74 additions & 22 deletions crates/oxc_linter/src/snapshots/no_commented_out_tests.snap
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
Expand All @@ -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]
2foo()
3 │ ╭─▶ /*
Expand All @@ -164,3 +165,54 @@ source: crates/oxc_linter/src/tester.rs
6bar()
╰────
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
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 @@ -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",
Expand Down

0 comments on commit 27fdd69

Please sign in to comment.