Skip to content

Commit b7b4f0f

Browse files
authored
fix: fix types (#632)
1 parent 06896aa commit b7b4f0f

File tree

2 files changed

+48
-54
lines changed

2 files changed

+48
-54
lines changed

src/index.ts

+44-51
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { Linter, RuleModule } from '@typescript-eslint/utils/ts-eslint'
1+
import type { Linter } from '@typescript-eslint/utils/ts-eslint'
2+
import type { ESLint } from "eslint"
23
import { version } from '../package.json'
34
import lowerCaseTitle, { RULE_NAME as lowerCaseTitleName } from './rules/prefer-lowercase-title'
45
import maxNestedDescribe, { RULE_NAME as maxNestedDescribeName } from './rules/max-nested-describe'
@@ -70,8 +71,8 @@ const createConfig = <R extends Linter.RulesRecord>(rules: R) => (
7071
[`vitest/${ruleName}`]: rules[ruleName]
7172
}
7273
}, {})) as {
73-
[K in keyof R as `vitest/${Extract<K, string>}`]: R[K]
74-
}
74+
[K in keyof R as `vitest/${Extract<K, string>}`]: R[K]
75+
}
7576

7677
const createConfigLegacy = (rules: Record<string, string>) => ({
7778
plugins: ['@vitest'],
@@ -159,23 +160,12 @@ const recommended = {
159160
[noImportNodeTestName]: 'error'
160161
} as const
161162

162-
interface VitestPlugin extends Linter.Plugin {
163-
meta: {
164-
name: string
165-
version: string
166-
}
167-
rules: Record<string, RuleModule<any, any>>
168-
// TODO: use classic type for config
169-
configs: Record<string, any>
170-
environments?: Record<string, any>
171-
}
172163

173-
const plugin: VitestPlugin = {
164+
const plugin = {
174165
meta: {
175166
name: 'vitest',
176167
version
177168
},
178-
configs: {},
179169
rules: {
180170
[lowerCaseTitleName]: lowerCaseTitle,
181171
[maxNestedDescribeName]: maxNestedDescribe,
@@ -261,46 +251,49 @@ const plugin: VitestPlugin = {
261251
onTestFinished: true
262252
}
263253
}
264-
}
265-
}
266-
267-
plugin.configs = {
268-
'legacy-recommended': createConfigLegacy(recommended),
269-
'legacy-all': createConfigLegacy(allRules),
270-
'recommended': {
271-
plugins: {
272-
['vitest']: plugin
273-
},
274-
rules: createConfig(recommended)
275254
},
276-
'all': {
277-
plugins: {
278-
['vitest']: plugin
255+
configs: {
256+
'legacy-recommended': createConfigLegacy(recommended),
257+
'legacy-all': createConfigLegacy(allRules),
258+
'recommended': {
259+
plugins: {
260+
get vitest(): ESLint.Plugin {
261+
return plugin
262+
}
263+
},
264+
rules: createConfig(recommended)
279265
},
280-
rules: createConfig(allRules)
281-
},
282-
'env': {
283-
languageOptions: {
284-
globals: {
285-
suite: 'writable',
286-
test: 'writable',
287-
describe: 'writable',
288-
it: 'writable',
289-
expectTypeOf: 'writable',
290-
assertType: 'writable',
291-
expect: 'writable',
292-
assert: 'writable',
293-
vitest: 'writable',
294-
vi: 'writable',
295-
beforeAll: 'writable',
296-
afterAll: 'writable',
297-
beforeEach: 'writable',
298-
afterEach: 'writable',
299-
onTestFailed: 'writable',
300-
onTestFinished: 'writable'
266+
'all': {
267+
plugins: {
268+
get vitest(): ESLint.Plugin {
269+
return plugin
270+
}
271+
},
272+
rules: createConfig(allRules)
273+
},
274+
'env': {
275+
languageOptions: {
276+
globals: {
277+
suite: 'writable',
278+
test: 'writable',
279+
describe: 'writable',
280+
it: 'writable',
281+
expectTypeOf: 'writable',
282+
assertType: 'writable',
283+
expect: 'writable',
284+
assert: 'writable',
285+
vitest: 'writable',
286+
vi: 'writable',
287+
beforeAll: 'writable',
288+
afterAll: 'writable',
289+
beforeEach: 'writable',
290+
afterEach: 'writable',
291+
onTestFailed: 'writable',
292+
onTestFinished: 'writable'
293+
}
301294
}
302295
}
303296
}
304-
}
297+
} satisfies ESLint.Plugin
305298

306299
export default plugin

src/utils/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ import {
1010
KnownMemberExpression,
1111
ParsedExpectVitestFnCall
1212
} from './parse-vitest-fn-call'
13-
import { RuleListener, RuleModule } from '@typescript-eslint/utils/ts-eslint'
13+
import { Rule } from "eslint"
1414

1515
export interface PluginDocs {
1616
recommended?: boolean
1717
requiresTypeChecking?: boolean
1818
}
1919

20-
export function createEslintRule<TOptions extends readonly unknown[], TMessageIds extends string>(rule: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, PluginDocs>>): RuleModule<TMessageIds, TOptions, PluginDocs, RuleListener> {
20+
export function createEslintRule<TOptions extends readonly unknown[], TMessageIds extends string>(rule: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, PluginDocs>>) {
2121
const createRule = ESLintUtils.RuleCreator<PluginDocs>(
2222
ruleName =>
2323
`https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/${ruleName}.md`
2424
)
25-
return createRule(rule)
25+
26+
return createRule(rule) as unknown as Rule.RuleModule
2627
}
2728

2829
export const joinNames = (a: string | null, b: string | null): string | null =>

0 commit comments

Comments
 (0)