1- import type { ESLint } from 'eslint'
1+ import type { ESLint , Linter } from 'eslint'
22import { version } from '../package.json'
33import lowerCaseTitle , { RULE_NAME as lowerCaseTitleName } from './rules/prefer-lowercase-title'
44import maxNestedDescribe , { RULE_NAME as maxNestedDescribeName } from './rules/max-nested-describe'
@@ -53,13 +53,15 @@ import preferComparisonMatcher, { RULE_NAME as preferComparisonMatcherName } fro
5353import preferToContain , { RULE_NAME as preferToContainName } from './rules/prefer-to-contain'
5454import preferExpectAssertions , { RULE_NAME as preferExpectAssertionsName } from './rules/prefer-expect-assertions'
5555
56- const createConfig = ( rules : Record < string , string > ) => (
56+ const createConfig = < R extends Linter . RulesRecord > ( rules : R ) => (
5757 Object . keys ( rules ) . reduce ( ( acc , ruleName ) => {
5858 return {
5959 ...acc ,
6060 [ `vitest/${ ruleName } ` ] : rules [ ruleName ]
6161 }
62- } , { } ) )
62+ } , { } ) ) as {
63+ [ K in keyof R as `vitest/${Extract < K , string > } `] : R [ K ]
64+ }
6365
6466const allRules = {
6567 [ lowerCaseTitleName ] : 'warn' ,
@@ -106,7 +108,7 @@ const allRules = {
106108 [ preferToContainName ] : 'warn' ,
107109 [ preferExpectAssertionsName ] : 'warn' ,
108110 [ usePreferTobe ] : 'warn'
109- }
111+ } as const
110112
111113const recommended = {
112114 [ expectedExpect ] : 'error' ,
@@ -117,7 +119,7 @@ const recommended = {
117119 [ validDescribeCallbackName ] : 'error' ,
118120 [ requireLocalTestContextForConcurrentSnapshotsName ] : 'error' ,
119121 [ noImportNodeTestName ] : 'error'
120- }
122+ } as const
121123
122124const plugin = {
123125 meta : {
@@ -178,7 +180,42 @@ const plugin = {
178180 [ preferToContainName ] : preferToContain ,
179181 [ preferExpectAssertionsName ] : preferExpectAssertions
180182 } ,
181- configs : { } ,
183+ configs : {
184+ recommended : {
185+ plugins : {
186+ get vitest ( ) : ESLint . Plugin {
187+ return plugin
188+ }
189+ } ,
190+ rules : createConfig ( recommended )
191+ } ,
192+ all : {
193+ plugins : {
194+ get vitest ( ) : ESLint . Plugin {
195+ return plugin
196+ }
197+ } ,
198+ rules : createConfig ( allRules )
199+ } ,
200+ env : {
201+ languageOptions : {
202+ globals : {
203+ suite : 'writable' ,
204+ test : 'writable' ,
205+ describe : 'writable' ,
206+ it : 'writable' ,
207+ expect : 'writable' ,
208+ assert : 'writable' ,
209+ vitest : 'writable' ,
210+ vi : 'writable' ,
211+ beforeAll : 'writable' ,
212+ afterAll : 'writable' ,
213+ beforeEach : 'writable' ,
214+ afterEach : 'writable'
215+ }
216+ }
217+ }
218+ } ,
182219 environments : {
183220 env : {
184221 globals : {
@@ -199,44 +236,4 @@ const plugin = {
199236 }
200237} satisfies ESLint . Plugin
201238
202- Object . assign ( plugin . configs , {
203- recommended : {
204- plugins : {
205- vitest : plugin
206- } ,
207- rules : createConfig ( recommended )
208- }
209- } )
210-
211- Object . assign ( plugin . configs , {
212- all : {
213- plugins : {
214- vitest : plugin
215- } ,
216- rules : createConfig ( allRules )
217- }
218- } )
219-
220- Object . assign ( plugin . configs , {
221- env : {
222- languageOptions : {
223- globals : {
224- suite : 'writeable' ,
225- test : 'writeable' ,
226- describe : 'writeable' ,
227- it : 'writeable' ,
228- expect : 'writeable' ,
229- assert : 'writeable' ,
230- vitest : 'writeable' ,
231- vi : 'writeable' ,
232- beforeAll : 'writeable' ,
233- afterAll : 'writeable' ,
234- beforeEach : 'writeable' ,
235- afterEach : 'writeable'
236- }
237-
238- }
239- }
240- } )
241-
242239export default plugin
0 commit comments