Skip to content

Commit 07c9d20

Browse files
authored
feat: add support for using vitest (#29)
1 parent 87dc3d5 commit 07c9d20

File tree

3 files changed

+118
-57
lines changed

3 files changed

+118
-57
lines changed

eslint/main.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
22
import eslint from '@eslint/js'
33
import neslint from 'eslint-plugin-n'
44
import tseslint from 'typescript-eslint'
5-
import jestPlugin from 'eslint-plugin-jest'
65
import sofiePlugin from '@sofie-automation/eslint-plugin'
76

87
/**
@@ -23,10 +22,17 @@ function compactObj(obj) {
2322
}
2423

2524
/**
26-
* @param {{ ignores?: string[], tsconfigName?: string | string[], disableNodeRules?: boolean }} options
25+
* @param {{ ignores?: string[], tsconfigName?: string | string[], disableNodeRules?: boolean, testRunner?: 'jest' | 'vitest' = 'jest' }} options
2726
* @returns {Promise<import('eslint').Linter.FlatConfig[]>}
2827
*/
2928
export async function generateEslintConfig(options) {
29+
// Conditionally load the testRunner plugin
30+
const jestPlugin =
31+
options.testRunner === undefined && options.testRunner === 'jest'
32+
? (await import('eslint-plugin-jest')).default
33+
: null
34+
const vitestPlugin = options.testRunner === 'vitest' ? (await import('@vitest/eslint-plugin')).default : null
35+
3036
return [
3137
{
3238
// Setup the parser for js/ts
@@ -77,6 +83,7 @@ export async function generateEslintConfig(options) {
7783
// @ts-expect-error tseslint type mismatch
7884
plugins: compactObj({
7985
jest: jestPlugin,
86+
vitest: vitestPlugin,
8087
'@typescript-eslint': tseslint.plugin,
8188
'@sofie-automation': sofiePlugin,
8289
}),
@@ -151,6 +158,16 @@ export async function generateEslintConfig(options) {
151158
},
152159
}
153160
: null,
161+
vitestPlugin
162+
? {
163+
// enable vitest rules on test files
164+
files: ['**/__tests__/**/*', 'test/**/*'],
165+
...vitestPlugin.configs.recommended,
166+
rules: {
167+
...vitestPlugin.configs.recommended.rules,
168+
},
169+
}
170+
: null,
154171
{
155172
files: ['**/__tests__/**/*', 'test/**/*'],
156173
rules: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
],
5050
"dependencies": {
5151
"@sofie-automation/eslint-plugin": "0.2.0",
52+
"@vitest/eslint-plugin": "^1.2.1",
5253
"date-fns": "^4.1.0",
5354
"eslint-config-prettier": "^10.0.1",
5455
"eslint-plugin-jest": "^28.11.0",

yarn.lock

Lines changed: 98 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ __metadata:
2323
languageName: node
2424
linkType: hard
2525

26-
"@eslint-community/eslint-utils@npm:^4.1.2, @eslint-community/eslint-utils@npm:^4.4.0, @eslint-community/eslint-utils@npm:^4.4.1":
27-
version: 4.4.1
28-
resolution: "@eslint-community/eslint-utils@npm:4.4.1"
26+
"@eslint-community/eslint-utils@npm:^4.1.2, @eslint-community/eslint-utils@npm:^4.4.0, @eslint-community/eslint-utils@npm:^4.4.1, @eslint-community/eslint-utils@npm:^4.7.0":
27+
version: 4.7.0
28+
resolution: "@eslint-community/eslint-utils@npm:4.7.0"
2929
dependencies:
3030
eslint-visitor-keys: "npm:^3.4.3"
3131
peerDependencies:
3232
eslint: ^6.0.0 || ^7.0.0 || >=8.0.0
33-
checksum: 10c0/2aa0ac2fc50ff3f234408b10900ed4f1a0b19352f21346ad4cc3d83a1271481bdda11097baa45d484dd564c895e0762a27a8240be7a256b3ad47129e96528252
33+
checksum: 10c0/c0f4f2bd73b7b7a9de74b716a664873d08ab71ab439e51befe77d61915af41a81ecec93b408778b3a7856185244c34c2c8ee28912072ec14def84ba2dec70adf
3434
languageName: node
3535
linkType: hard
3636

@@ -81,6 +81,7 @@ __metadata:
8181
dependencies:
8282
"@sofie-automation/eslint-plugin": "npm:0.2.0"
8383
"@types/eslint": "npm:^9.6.1"
84+
"@vitest/eslint-plugin": "npm:^1.2.1"
8485
date-fns: "npm:^4.1.0"
8586
eslint-config-prettier: "npm:^10.0.1"
8687
eslint-plugin-jest: "npm:^28.11.0"
@@ -181,13 +182,16 @@ __metadata:
181182
languageName: node
182183
linkType: hard
183184

184-
"@typescript-eslint/scope-manager@npm:8.20.0":
185-
version: 8.20.0
186-
resolution: "@typescript-eslint/scope-manager@npm:8.20.0"
185+
"@typescript-eslint/project-service@npm:8.33.1":
186+
version: 8.33.1
187+
resolution: "@typescript-eslint/project-service@npm:8.33.1"
187188
dependencies:
188-
"@typescript-eslint/types": "npm:8.20.0"
189-
"@typescript-eslint/visitor-keys": "npm:8.20.0"
190-
checksum: 10c0/a8074768d06c863169294116624a45c19377ff0b8635ad5fa4ae673b43cf704d1b9b79384ceef0ff0abb78b107d345cd90fe5572354daf6ad773fe462ee71e6a
189+
"@typescript-eslint/tsconfig-utils": "npm:^8.33.1"
190+
"@typescript-eslint/types": "npm:^8.33.1"
191+
debug: "npm:^4.3.4"
192+
peerDependencies:
193+
typescript: ">=4.8.4 <5.9.0"
194+
checksum: 10c0/b2ff7653aef4648bdff8aafc69b9de434184827216709f8a36427536ac7082a8adf1c5ac12a0a2bb023b46dfad8f6fee238028acc94af622956af7f22362de6f
191195
languageName: node
192196
linkType: hard
193197

@@ -201,6 +205,25 @@ __metadata:
201205
languageName: node
202206
linkType: hard
203207

208+
"@typescript-eslint/scope-manager@npm:8.33.1":
209+
version: 8.33.1
210+
resolution: "@typescript-eslint/scope-manager@npm:8.33.1"
211+
dependencies:
212+
"@typescript-eslint/types": "npm:8.33.1"
213+
"@typescript-eslint/visitor-keys": "npm:8.33.1"
214+
checksum: 10c0/03a6fd2b0a8ebeb62083a8f51658f0c42391cbfb632411542569a3a227d53bdb0332026ef4d5adc4780e5350d1d8b89e5b19667ed899afd26506e60c70192692
215+
languageName: node
216+
linkType: hard
217+
218+
"@typescript-eslint/tsconfig-utils@npm:8.33.1, @typescript-eslint/tsconfig-utils@npm:^8.33.1":
219+
version: 8.33.1
220+
resolution: "@typescript-eslint/tsconfig-utils@npm:8.33.1"
221+
peerDependencies:
222+
typescript: ">=4.8.4 <5.9.0"
223+
checksum: 10c0/242e8f271d2e6e51446d337e1e59e8c91b66c0241da0fb861f536eb86cc3b53d1727c41e12e1ba070fa2451c8bc517c1ec50decaffa92a7c612b2aba29872777
224+
languageName: node
225+
linkType: hard
226+
204227
"@typescript-eslint/type-utils@npm:8.21.0":
205228
version: 8.21.0
206229
resolution: "@typescript-eslint/type-utils@npm:8.21.0"
@@ -216,26 +239,26 @@ __metadata:
216239
languageName: node
217240
linkType: hard
218241

219-
"@typescript-eslint/types@npm:8.20.0":
220-
version: 8.20.0
221-
resolution: "@typescript-eslint/types@npm:8.20.0"
222-
checksum: 10c0/21292d4ca089897015d2bf5ab99909a7b362902f63f4ba10696676823b50d00c7b4cd093b4b43fba01d12bc3feca3852d2c28528c06d8e45446b7477887dbee7
223-
languageName: node
224-
linkType: hard
225-
226242
"@typescript-eslint/types@npm:8.21.0":
227243
version: 8.21.0
228244
resolution: "@typescript-eslint/types@npm:8.21.0"
229245
checksum: 10c0/67dfd300cc614d7b02e94d0dacfb228a7f4c3fd4eede29c43adb9e9fcc16365ae3df8d6165018da3c123dce65545bef03e3e8183f35e9b3a911ffc727e3274c2
230246
languageName: node
231247
linkType: hard
232248

233-
"@typescript-eslint/typescript-estree@npm:8.20.0":
234-
version: 8.20.0
235-
resolution: "@typescript-eslint/typescript-estree@npm:8.20.0"
249+
"@typescript-eslint/types@npm:8.33.1, @typescript-eslint/types@npm:^8.33.1":
250+
version: 8.33.1
251+
resolution: "@typescript-eslint/types@npm:8.33.1"
252+
checksum: 10c0/3083c184c882475eed1f9d1a8961dad30ef834c662bc826ff9a959ff1eed49aad21a73b2b93c4062799feafff5f5f24aebb1df17e198808aa19d4c8de1e64095
253+
languageName: node
254+
linkType: hard
255+
256+
"@typescript-eslint/typescript-estree@npm:8.21.0":
257+
version: 8.21.0
258+
resolution: "@typescript-eslint/typescript-estree@npm:8.21.0"
236259
dependencies:
237-
"@typescript-eslint/types": "npm:8.20.0"
238-
"@typescript-eslint/visitor-keys": "npm:8.20.0"
260+
"@typescript-eslint/types": "npm:8.21.0"
261+
"@typescript-eslint/visitor-keys": "npm:8.21.0"
239262
debug: "npm:^4.3.4"
240263
fast-glob: "npm:^3.3.2"
241264
is-glob: "npm:^4.0.3"
@@ -244,29 +267,31 @@ __metadata:
244267
ts-api-utils: "npm:^2.0.0"
245268
peerDependencies:
246269
typescript: ">=4.8.4 <5.8.0"
247-
checksum: 10c0/54a2c1da7d1c5f7e865b941e8a3c98eb4b5f56ed8741664a84065173bde9602cdb8866b0984b26816d6af885c1528311c11e7286e869ed424483b74366514cbd
270+
checksum: 10c0/0cf5b0382524f4af54fb5ec71ca7e939ec922711f2d77b383740b28dd4b21407b0ab5dded62df6819d01c12c0b354e95667e3c7025a5d27d05b805161ab94855
248271
languageName: node
249272
linkType: hard
250273

251-
"@typescript-eslint/typescript-estree@npm:8.21.0":
252-
version: 8.21.0
253-
resolution: "@typescript-eslint/typescript-estree@npm:8.21.0"
274+
"@typescript-eslint/typescript-estree@npm:8.33.1":
275+
version: 8.33.1
276+
resolution: "@typescript-eslint/typescript-estree@npm:8.33.1"
254277
dependencies:
255-
"@typescript-eslint/types": "npm:8.21.0"
256-
"@typescript-eslint/visitor-keys": "npm:8.21.0"
278+
"@typescript-eslint/project-service": "npm:8.33.1"
279+
"@typescript-eslint/tsconfig-utils": "npm:8.33.1"
280+
"@typescript-eslint/types": "npm:8.33.1"
281+
"@typescript-eslint/visitor-keys": "npm:8.33.1"
257282
debug: "npm:^4.3.4"
258283
fast-glob: "npm:^3.3.2"
259284
is-glob: "npm:^4.0.3"
260285
minimatch: "npm:^9.0.4"
261286
semver: "npm:^7.6.0"
262-
ts-api-utils: "npm:^2.0.0"
287+
ts-api-utils: "npm:^2.1.0"
263288
peerDependencies:
264-
typescript: ">=4.8.4 <5.8.0"
265-
checksum: 10c0/0cf5b0382524f4af54fb5ec71ca7e939ec922711f2d77b383740b28dd4b21407b0ab5dded62df6819d01c12c0b354e95667e3c7025a5d27d05b805161ab94855
289+
typescript: ">=4.8.4 <5.9.0"
290+
checksum: 10c0/293a93d25046e05fdc3887232191c3f3ee771c0f5b1426d63deaf0541db1cb80b4307a80805c78b092206c9b267884a7e6b5905dc1b3c26f28bb4de47fd9ee8f
266291
languageName: node
267292
linkType: hard
268293

269-
"@typescript-eslint/utils@npm:8.21.0, @typescript-eslint/utils@npm:^8.21.0":
294+
"@typescript-eslint/utils@npm:8.21.0":
270295
version: 8.21.0
271296
resolution: "@typescript-eslint/utils@npm:8.21.0"
272297
dependencies:
@@ -281,28 +306,18 @@ __metadata:
281306
languageName: node
282307
linkType: hard
283308

284-
"@typescript-eslint/utils@npm:^6.0.0 || ^7.0.0 || ^8.0.0":
285-
version: 8.20.0
286-
resolution: "@typescript-eslint/utils@npm:8.20.0"
309+
"@typescript-eslint/utils@npm:^6.0.0 || ^7.0.0 || ^8.0.0, @typescript-eslint/utils@npm:^8.21.0, @typescript-eslint/utils@npm:^8.24.0":
310+
version: 8.33.1
311+
resolution: "@typescript-eslint/utils@npm:8.33.1"
287312
dependencies:
288-
"@eslint-community/eslint-utils": "npm:^4.4.0"
289-
"@typescript-eslint/scope-manager": "npm:8.20.0"
290-
"@typescript-eslint/types": "npm:8.20.0"
291-
"@typescript-eslint/typescript-estree": "npm:8.20.0"
313+
"@eslint-community/eslint-utils": "npm:^4.7.0"
314+
"@typescript-eslint/scope-manager": "npm:8.33.1"
315+
"@typescript-eslint/types": "npm:8.33.1"
316+
"@typescript-eslint/typescript-estree": "npm:8.33.1"
292317
peerDependencies:
293318
eslint: ^8.57.0 || ^9.0.0
294-
typescript: ">=4.8.4 <5.8.0"
295-
checksum: 10c0/dd36c3b22a2adde1e1462aed0c8b4720f61859b4ebb0c3ef935a786a6b1cb0ec21eb0689f5a8debe8db26d97ebb979bab68d6f8fe7b0098e6200a485cfe2991b
296-
languageName: node
297-
linkType: hard
298-
299-
"@typescript-eslint/visitor-keys@npm:8.20.0":
300-
version: 8.20.0
301-
resolution: "@typescript-eslint/visitor-keys@npm:8.20.0"
302-
dependencies:
303-
"@typescript-eslint/types": "npm:8.20.0"
304-
eslint-visitor-keys: "npm:^4.2.0"
305-
checksum: 10c0/e95d8b2685e8beb6637bf2e9d06e4177a400d3a2b142ba749944690f969ee3186b750082fd9bf34ada82acf1c5dd5970201dfd97619029c8ecca85fb4b50dbd8
319+
typescript: ">=4.8.4 <5.9.0"
320+
checksum: 10c0/12263df6eb32e8175236ad899687c062b50cfe4a0e66307d25ad2bf85a3e911faacbfbea4df180a59ebb5913fe1cc1f53fe3914695c7d802dd318bbc846fea26
306321
languageName: node
307322
linkType: hard
308323

@@ -316,6 +331,34 @@ __metadata:
316331
languageName: node
317332
linkType: hard
318333

334+
"@typescript-eslint/visitor-keys@npm:8.33.1":
335+
version: 8.33.1
336+
resolution: "@typescript-eslint/visitor-keys@npm:8.33.1"
337+
dependencies:
338+
"@typescript-eslint/types": "npm:8.33.1"
339+
eslint-visitor-keys: "npm:^4.2.0"
340+
checksum: 10c0/3eb99072e7c2741d5dfc38945d1e7617b15ed10d06b24658a6e919e4153983b3d3c5f5f775ce140f83a84dbde219948d187de97defb09c1a91f3cf0a96704a94
341+
languageName: node
342+
linkType: hard
343+
344+
"@vitest/eslint-plugin@npm:^1.2.1":
345+
version: 1.2.1
346+
resolution: "@vitest/eslint-plugin@npm:1.2.1"
347+
dependencies:
348+
"@typescript-eslint/utils": "npm:^8.24.0"
349+
peerDependencies:
350+
eslint: ">= 8.57.0"
351+
typescript: ">= 5.0.0"
352+
vitest: "*"
353+
peerDependenciesMeta:
354+
typescript:
355+
optional: true
356+
vitest:
357+
optional: true
358+
checksum: 10c0/b2c8211225d4bb738cf246f49add938466207f66043fdbff9263a0789f004b215b3c9443842a6f43f93b877ab960622191a54d82149c1af74b039d5d17aa8f6d
359+
languageName: node
360+
linkType: hard
361+
319362
"abbrev@npm:1":
320363
version: 1.1.1
321364
resolution: "abbrev@npm:1.1.1"
@@ -1302,12 +1345,12 @@ __metadata:
13021345
languageName: node
13031346
linkType: hard
13041347

1305-
"ts-api-utils@npm:^2.0.0":
1306-
version: 2.0.0
1307-
resolution: "ts-api-utils@npm:2.0.0"
1348+
"ts-api-utils@npm:^2.0.0, ts-api-utils@npm:^2.1.0":
1349+
version: 2.1.0
1350+
resolution: "ts-api-utils@npm:2.1.0"
13081351
peerDependencies:
13091352
typescript: ">=4.8.4"
1310-
checksum: 10c0/6165e29a5b75bd0218e3cb0f9ee31aa893dbd819c2e46dbb086c841121eb0436ed47c2c18a20cb3463d74fd1fb5af62e2604ba5971cc48e5b38ebbdc56746dfc
1353+
checksum: 10c0/9806a38adea2db0f6aa217ccc6bc9c391ddba338a9fe3080676d0d50ed806d305bb90e8cef0276e793d28c8a929f400abb184ddd7ff83a416959c0f4d2ce754f
13111354
languageName: node
13121355
linkType: hard
13131356

0 commit comments

Comments
 (0)