Skip to content

Commit bc95b10

Browse files
authored
feat: Add rule to recommended Vitest ESLint config (#827)
* feat: add recommended rules for testing best practices * docs: update docs
1 parent 54be66e commit bc95b10

File tree

9 files changed

+94
-87
lines changed

9 files changed

+94
-87
lines changed

README.md

Lines changed: 80 additions & 80 deletions
Large diffs are not rendered by default.

docs/rules/no-conditional-expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow conditional expects (`vitest/no-conditional-expect`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.
44

55
<!-- end auto-generated rule header -->
66

docs/rules/no-disabled-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow disabled tests (`vitest/no-disabled-tests`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
⚠️ This rule _warns_ in the following configs: 🌐 `all`, ✅ `recommended`.
44

55
<!-- end auto-generated rule header -->
66

docs/rules/no-focused-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow focused tests (`vitest/no-focused-tests`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.
44

55
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
66

docs/rules/no-interpolation-in-snapshots.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow string interpolation in snapshots (`vitest/no-interpolation-in-snapshots`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.
44

55
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
66

docs/rules/no-mocks-import.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow importing from **mocks** directory (`vitest/no-mocks-import`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.
44

55
<!-- end auto-generated rule header -->
66

docs/rules/no-standalone-expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Disallow using `expect` outside of `it` or `test` blocks (`vitest/no-standalone-expect`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.
44

55
<!-- end auto-generated rule header -->
66

docs/rules/valid-expect-in-promise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Require promises that have expectations in their chain to be valid (`vitest/valid-expect-in-promise`)
22

3-
⚠️ This rule _warns_ in the 🌐 `all` config.
3+
💼⚠️ This rule is enabled in the ✅ `recommended` config. This rule _warns_ in the 🌐 `all` config.
44

55
<!-- end auto-generated rule header -->
66

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ const allRules = {
103103

104104
const recommendedRules = {
105105
'expect-expect': 'error',
106+
'no-conditional-expect': 'error',
107+
'no-disabled-tests': 'warn',
108+
'no-focused-tests': 'error',
106109
'no-commented-out-tests': 'error',
107110
'no-identical-title': 'error',
108111
'no-import-node-test': 'error',
112+
'no-interpolation-in-snapshots': 'error',
113+
'no-mocks-import': 'error',
114+
'no-standalone-expect': 'error',
109115
'prefer-called-exactly-once-with': 'error',
110116
'require-local-test-context-for-concurrent-snapshots': 'error',
111117
'valid-describe-callback': 'error',
112118
'valid-expect': 'error',
119+
'valid-expect-in-promise': 'error',
113120
'valid-title': 'error',
114121
} as const satisfies RuleList
115122

0 commit comments

Comments
 (0)