Skip to content

Commit 37a8b11

Browse files
chore(eslint): migrate from eslint-plugin-vitest to @vitest/eslint-plugin and run rules only on test files (#4014)
This PR makes three small changes to the ESLint setup: 1. Migrate from [eslint-plugin-vitest](https://www.npmjs.com/package/eslint-plugin-vitest) to it's successor [@vitest/eslint-plugin](https://www.npmjs.com/package/@vitest/eslint-plugin). 2. Change the eslint config so that only the test files are checked with the vitest rules. Previously, it was just unnecessary and inefficient to check all js files with them. 3. We had defined some of the test rules as warnings, but that is not really ideal. I changed them to errors.
1 parent 2d3a557 commit 37a8b11

File tree

3 files changed

+212
-197
lines changed

3 files changed

+212
-197
lines changed

eslint.config.mjs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import jsdocPlugin from "eslint-plugin-jsdoc";
66
import packageJson from "eslint-plugin-package-json";
77
import playwright from "eslint-plugin-playwright";
88
import stylistic from "@stylistic/eslint-plugin";
9-
import vitest from "eslint-plugin-vitest";
9+
import vitest from "@vitest/eslint-plugin";
1010

1111
export default defineConfig([
1212
globalIgnores(["config/**", "modules/**/*", "!modules/default/**", "js/positions.js"]),
@@ -17,16 +17,15 @@ export default defineConfig([
1717
globals: {
1818
...globals.browser,
1919
...globals.node,
20-
...vitest.environments.env.globals,
2120
Log: "readonly",
2221
MM: "readonly",
2322
Module: "readonly",
2423
config: "readonly",
2524
moment: "readonly"
2625
}
2726
},
28-
plugins: {js, stylistic, vitest},
29-
extends: [importX.recommended, vitest.configs.recommended, "js/recommended", jsdocPlugin.configs["flat/recommended"], "stylistic/all"],
27+
plugins: {js, stylistic},
28+
extends: [importX.recommended, "js/recommended", jsdocPlugin.configs["flat/recommended"], "stylistic/all"],
3029
rules: {
3130
"@stylistic/array-element-newline": ["error", "consistent"],
3231
"@stylistic/arrow-parens": ["error", "always"],
@@ -59,23 +58,6 @@ export default defineConfig([
5958
"import-x/newline-after-import": "error",
6059
"import-x/order": "error",
6160
"init-declarations": "off",
62-
"vitest/consistent-test-it": "warn",
63-
"vitest/expect-expect": [
64-
"warn",
65-
{
66-
assertFunctionNames: [
67-
"expect",
68-
"testElementLength",
69-
"testTextContain",
70-
"doTest",
71-
"runAnimationTest",
72-
"waitForAnimationClass",
73-
"assertNoAnimationWithin"
74-
]
75-
}
76-
],
77-
"vitest/prefer-to-be": "warn",
78-
"vitest/prefer-to-have-length": "warn",
7961
"max-lines-per-function": ["warn", 400],
8062
"max-statements": "off",
8163
"no-global-assign": "off",
@@ -135,6 +117,36 @@ export default defineConfig([
135117
"sort-keys": "off"
136118
}
137119
},
120+
{
121+
files: ["tests/**/*.js"],
122+
languageOptions: {
123+
globals: {
124+
...vitest.environments.env.globals
125+
}
126+
},
127+
plugins: {vitest},
128+
extends: [vitest.configs.recommended],
129+
rules: {
130+
"vitest/consistent-test-it": "error",
131+
"vitest/expect-expect": [
132+
"error",
133+
{
134+
assertFunctionNames: [
135+
"expect",
136+
"testElementLength",
137+
"testTextContain",
138+
"doTest",
139+
"runAnimationTest",
140+
"waitForAnimationClass",
141+
"assertNoAnimationWithin"
142+
]
143+
}
144+
],
145+
"vitest/max-nested-describe": ["error", {max: 3}],
146+
"vitest/prefer-to-be": "error",
147+
"vitest/prefer-to-have-length": "error"
148+
}
149+
},
138150
{
139151
files: ["tests/configs/modules/weather/*.js"],
140152
rules: {

0 commit comments

Comments
 (0)