From ec2366eb49e4c74ed7cdf834eaf4dc7ae4ae7a47 Mon Sep 17 00:00:00 2001 From: Yukihiro Hasegawa <49516827+y-hsgw@users.noreply.github.com> Date: Sun, 1 Dec 2024 14:25:00 +0900 Subject: [PATCH] Enhance "all" configuration and update documentation (#578) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: update all rules * docs: update README * update: delete of "⚠️ This rule _warns_ in the 🌐 `all` config." * Revert "update: delete of "⚠️ This rule _warns_ in the 🌐 `all` config."" This reverts commit a087a49f30f0254fb196fb52d0057199bf70c385. * docs: Add notes for all config to rule documentation * docs: fix readme * docs: fix readme --- README.md | 49 ++++++++++++++++--- docs/rules/expect-expect.md | 3 +- docs/rules/no-commented-out-tests.md | 2 + docs/rules/no-identical-title.md | 2 + docs/rules/no-import-node-test.md | 2 + ...l-test-context-for-concurrent-snapshots.md | 2 + docs/rules/valid-describe-callback.md | 16 +++--- docs/rules/valid-expect.md | 2 + docs/rules/valid-title.md | 2 + src/index.ts | 10 +++- 10 files changed, 73 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f57cdde3..a210a01c 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,39 @@ export default [ ] ``` +### Shareable configurations + +#### Recommended +This plugin exports a recommended configuration that enforces good testing practices. + +To enable this configuration with `eslint.config.js`, use `vitest.configs.recommended`: + +```js +import vitest from "@vitest/eslint-plugin"; + +export default [ + { + files: ["tests/**"], // or any other pattern + ...vitest.configs.recommended, + } +] +``` + + +#### All +If you want to enable all rules instead of only some you can do so by adding the all configuration to your `eslint.config.js` config file: + +```js +import vitest from "@vitest/eslint-plugin"; + +export default [ + { + files: ["tests/**"], // or any other pattern + ...vitest.configs.all, + } +] +``` + ### Rules @@ -122,11 +155,11 @@ export default [ | :----------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------- | :- | :- | :- | :- | :- | | [consistent-test-filename](docs/rules/consistent-test-filename.md) | require .spec test file pattern | | 🌐 | | | | | [consistent-test-it](docs/rules/consistent-test-it.md) | enforce using test or it but not both | | 🌐 | 🔧 | | | -| [expect-expect](docs/rules/expect-expect.md) | enforce having expectation in test body | ✅ | | | | | +| [expect-expect](docs/rules/expect-expect.md) | enforce having expectation in test body | ✅ | 🌐 | | | | | [max-expects](docs/rules/max-expects.md) | enforce a maximum number of expect per test | | 🌐 | | | | | [max-nested-describe](docs/rules/max-nested-describe.md) | require describe block to be less than set max value or default value | | 🌐 | | | | | [no-alias-methods](docs/rules/no-alias-methods.md) | disallow alias methods | | 🌐 | 🔧 | | | -| [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | disallow commented out tests | ✅ | | | | | +| [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | disallow commented out tests | ✅ | 🌐 | | | | | [no-conditional-expect](docs/rules/no-conditional-expect.md) | disallow conditional expects | | 🌐 | | | | | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | disallow conditional tests | | 🌐 | | | | | [no-conditional-tests](docs/rules/no-conditional-tests.md) | disallow conditional tests | | 🌐 | | | | @@ -135,8 +168,8 @@ export default [ | [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | disallow duplicate hooks and teardown hooks | | 🌐 | | | | | [no-focused-tests](docs/rules/no-focused-tests.md) | disallow focused tests | | 🌐 | 🔧 | | | | [no-hooks](docs/rules/no-hooks.md) | disallow setup and teardown hooks | | 🌐 | | | | -| [no-identical-title](docs/rules/no-identical-title.md) | disallow identical titles | ✅ | | 🔧 | | | -| [no-import-node-test](docs/rules/no-import-node-test.md) | disallow importing `node:test` | ✅ | | 🔧 | | | +| [no-identical-title](docs/rules/no-identical-title.md) | disallow identical titles | ✅ | 🌐 | 🔧 | | | +| [no-import-node-test](docs/rules/no-import-node-test.md) | disallow importing `node:test` | ✅ | 🌐 | 🔧 | | | | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | disallow string interpolation in snapshots | | 🌐 | 🔧 | | | | [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | 🌐 | | | | | [no-mocks-import](docs/rules/no-mocks-import.md) | disallow importing from __mocks__ directory | | 🌐 | | | | @@ -167,12 +200,12 @@ export default [ | [prefer-todo](docs/rules/prefer-todo.md) | enforce using `test.todo` | | 🌐 | 🔧 | | | | [prefer-vi-mocked](docs/rules/prefer-vi-mocked.md) | Prefer `vi.mocked()` over `fn as Mock` | | 🌐 | 🔧 | | | | [require-hook](docs/rules/require-hook.md) | require setup and teardown to be within a hook | | 🌐 | | | | -| [require-local-test-context-for-concurrent-snapshots](docs/rules/require-local-test-context-for-concurrent-snapshots.md) | require local Test Context for concurrent snapshot tests | ✅ | | | | | +| [require-local-test-context-for-concurrent-snapshots](docs/rules/require-local-test-context-for-concurrent-snapshots.md) | require local Test Context for concurrent snapshot tests | ✅ | 🌐 | | | | | [require-to-throw-message](docs/rules/require-to-throw-message.md) | require toThrow() to be called with an error message | | 🌐 | | | | | [require-top-level-describe](docs/rules/require-top-level-describe.md) | enforce that all tests are in a top-level describe | | 🌐 | | | | -| [valid-describe-callback](docs/rules/valid-describe-callback.md) | enforce valid describe callback | ✅ | | | | | -| [valid-expect](docs/rules/valid-expect.md) | enforce valid `expect()` usage | ✅ | | 🔧 | | | -| [valid-title](docs/rules/valid-title.md) | enforce valid titles | ✅ | | 🔧 | | | +| [valid-describe-callback](docs/rules/valid-describe-callback.md) | enforce valid describe callback | ✅ | 🌐 | | | | +| [valid-expect](docs/rules/valid-expect.md) | enforce valid `expect()` usage | ✅ | 🌐 | 🔧 | | | +| [valid-title](docs/rules/valid-title.md) | enforce valid titles | ✅ | 🌐 | 🔧 | | | diff --git a/docs/rules/expect-expect.md b/docs/rules/expect-expect.md index ee507870..0062825c 100644 --- a/docs/rules/expect-expect.md +++ b/docs/rules/expect-expect.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + @@ -88,4 +90,3 @@ checkForMe('myLogic', () => { }) }) ``` - diff --git a/docs/rules/no-commented-out-tests.md b/docs/rules/no-commented-out-tests.md index 1b0a17f8..7e189ada 100644 --- a/docs/rules/no-commented-out-tests.md +++ b/docs/rules/no-commented-out-tests.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + ## Rule Details diff --git a/docs/rules/no-identical-title.md b/docs/rules/no-identical-title.md index 6378e47e..a9705cf8 100644 --- a/docs/rules/no-identical-title.md +++ b/docs/rules/no-identical-title.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/no-import-node-test.md b/docs/rules/no-import-node-test.md index ab0bc2ff..79f27587 100644 --- a/docs/rules/no-import-node-test.md +++ b/docs/rules/no-import-node-test.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/require-local-test-context-for-concurrent-snapshots.md b/docs/rules/require-local-test-context-for-concurrent-snapshots.md index 23feef78..291e6326 100644 --- a/docs/rules/require-local-test-context-for-concurrent-snapshots.md +++ b/docs/rules/require-local-test-context-for-concurrent-snapshots.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + ## Rule details diff --git a/docs/rules/valid-describe-callback.md b/docs/rules/valid-describe-callback.md index 14d4520e..43ffadb4 100644 --- a/docs/rules/valid-describe-callback.md +++ b/docs/rules/valid-describe-callback.md @@ -2,12 +2,14 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + -This rule validates the second parameter of a `describe()` function is a callback. +This rule validates the second parameter of a `describe()` function is a callback. -- should not contain parameters +- should not contain parameters - should not contain any `return` statements The following are considered warnings: @@ -15,21 +17,21 @@ The following are considered warnings: ```js // callback function parameters are not allowed describe("myfunc", done => { - // + // }) describe("myfunc", () => { // no return statements are allowed in a block of a callback function return Promise.resolve().then(() => { - // + // }) }) -// returning a value from a describe block is not allowed +// returning a value from a describe block is not allowed describe("myfunc", () => { it("should do something", () => { - // + // }) }) ``` @@ -42,7 +44,7 @@ describe("myfunc", async () => { }) describe("myfunc", () => { it("should do something", () => { - // + // }) }) ``` diff --git a/docs/rules/valid-expect.md b/docs/rules/valid-expect.md index a9883975..6e98836f 100644 --- a/docs/rules/valid-expect.md +++ b/docs/rules/valid-expect.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/valid-title.md b/docs/rules/valid-title.md index 99388fef..d9e509a1 100644 --- a/docs/rules/valid-title.md +++ b/docs/rules/valid-title.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the ✅ `recommended` config. +⚠️ This rule _warns_ in the 🌐 `all` config. + 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/src/index.ts b/src/index.ts index 41b3114c..a648614c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,7 +137,15 @@ const allRules = { [paddingAroundDescribeBlocksName]: 'warn', [paddingAroundExpectGroupsName]: 'warn', [paddingAroundTestBlocksName]: 'warn', - [validExpectInPromiseName]: 'warn' + [validExpectInPromiseName]: 'warn', + [expectedExpect]: 'warn', + [noIdenticalTitleName]: 'warn', + [noCommentedOutTestsName]: 'warn', + [validTitleName]: 'warn', + [validExpectName]: 'warn', + [validDescribeCallbackName]: 'warn', + [requireLocalTestContextForConcurrentSnapshotsName]: 'warn', + [noImportNodeTestName]: 'warn' } as const const recommended = {