From 5f1aac92cd9fd4aac35ab14e15a0b1cc3b29236a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Verit=C3=A9=20Mugabo?= Date: Thu, 26 Dec 2024 12:23:33 -0500 Subject: [PATCH] make build work (#618) * make build work * improve eslint * feat: add custom plugin type --- package.json | 2 +- pnpm-lock.yaml | 14 +------ src/index.ts | 101 ++++++++++++++++++++++++--------------------- src/utils/index.ts | 18 ++++---- 4 files changed, 69 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 2adc75c3..01ecdf90 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@typescript-eslint/parser": "8.18.2", "@typescript-eslint/rule-tester": "8.18.1", "@vitest/eslint-plugin": "^1.1.20", - "bumpp": "^9.9.1", + "bumpp": "^9.9.2", "concurrently": "^8.2.2", "eslint": "^9.17.0", "eslint-doc-generator": "^2.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d2a3d76c..3d9b4575 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,7 +37,7 @@ importers: specifier: ^1.1.20 version: 1.1.20(@typescript-eslint/utils@8.18.1(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2))(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2)(vitest@2.1.8(@types/node@22.10.2)) bumpp: - specifier: ^9.9.1 + specifier: ^9.9.2 version: 9.9.2 concurrently: specifier: ^8.2.2 @@ -1288,10 +1288,6 @@ packages: typescript: optional: true - cross-spawn@7.0.3: - resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} - engines: {node: '>= 8'} - cross-spawn@7.0.6: resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} @@ -3733,12 +3729,6 @@ snapshots: optionalDependencies: typescript: 5.7.2 - cross-spawn@7.0.3: - dependencies: - path-key: 3.1.1 - shebang-command: 2.0.0 - which: 2.0.2 - cross-spawn@7.0.6: dependencies: path-key: 3.1.1 @@ -4104,7 +4094,7 @@ snapshots: execa@8.0.1: dependencies: - cross-spawn: 7.0.3 + cross-spawn: 7.0.6 get-stream: 8.0.1 human-signals: 5.0.0 is-stream: 3.0.0 diff --git a/src/index.ts b/src/index.ts index b839d831..9213a143 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import type { Linter } from 'eslint' +import type { Linter, RuleModule } from '@typescript-eslint/utils/ts-eslint' import { version } from '../package.json' import lowerCaseTitle, { RULE_NAME as lowerCaseTitleName } from './rules/prefer-lowercase-title' import maxNestedDescribe, { RULE_NAME as maxNestedDescribeName } from './rules/max-nested-describe' @@ -70,8 +70,8 @@ const createConfig = (rules: R) => ( [`vitest/${ruleName}`]: rules[ruleName] } }, {})) as { - [K in keyof R as `vitest/${Extract}`]: R[K] -} + [K in keyof R as `vitest/${Extract}`]: R[K] + } const createConfigLegacy = (rules: Record) => ({ plugins: ['@vitest'], @@ -159,7 +159,18 @@ const recommended = { [noImportNodeTestName]: 'error' } as const -const plugin = { +interface VitestPLugin extends Linter.Plugin { + meta: { + name: string + version: string + } + rules: Record> + //TODO: use classic type for config + configs?: Record + environments?: Record +} + +const plugin: VitestPLugin = { meta: { name: 'vitest', version @@ -228,48 +239,6 @@ const plugin = { [paddingAroundTestBlocksName]: paddingAroundTestBlocks, [validExpectInPromiseName]: validExpectInPromise }, - configs: { - 'legacy-recommended': createConfigLegacy(recommended), - 'legacy-all': createConfigLegacy(allRules), - 'recommended': { - plugins: { - get vitest() { - return plugin - } - }, - rules: createConfig(recommended) - }, - 'all': { - plugins: { - get vitest() { - return plugin - } - }, - rules: createConfig(allRules) - }, - 'env': { - languageOptions: { - globals: { - suite: 'writable', - test: 'writable', - describe: 'writable', - it: 'writable', - expectTypeOf: 'writable', - assertType: 'writable', - expect: 'writable', - assert: 'writable', - vitest: 'writable', - vi: 'writable', - beforeAll: 'writable', - afterAll: 'writable', - beforeEach: 'writable', - afterEach: 'writable', - onTestFailed: 'writable', - onTestFinished: 'writable' - } - } - } - }, environments: { env: { globals: { @@ -294,4 +263,44 @@ const plugin = { } } +plugin.configs = { + 'legacy-recommended': createConfigLegacy(recommended), + 'legacy-all': createConfigLegacy(allRules), + 'recommended': { + plugins: { + ["vitest"]: plugin + }, + rules: createConfig(recommended) + }, + 'all': { + plugins: { + ["vitest"]: plugin + }, + rules: createConfig(allRules) + }, + 'env': { + languageOptions: { + globals: { + suite: 'writable', + test: 'writable', + describe: 'writable', + it: 'writable', + expectTypeOf: 'writable', + assertType: 'writable', + expect: 'writable', + assert: 'writable', + vitest: 'writable', + vi: 'writable', + beforeAll: 'writable', + afterAll: 'writable', + beforeEach: 'writable', + afterEach: 'writable', + onTestFailed: 'writable', + onTestFinished: 'writable' + } + } + } +} + + export default plugin diff --git a/src/utils/index.ts b/src/utils/index.ts index f6d59216..ce922f00 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -10,20 +10,24 @@ import { KnownMemberExpression, ParsedExpectVitestFnCall } from './parse-vitest-fn-call' +import { RuleRecommendation, RuleRecommendationAcrossConfigs } from '@typescript-eslint/utils/ts-eslint' interface PluginDocs { recommended?: boolean requiresTypeChecking?: boolean + extendsBaseRule?: boolean | string; } -export function createEslintRule(rule: Readonly>) { - const createRule = ESLintUtils.RuleCreator( - ruleName => - `https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/${ruleName}.md` - ) - return createRule(rule) -} +// export function createEslintRule(rule: Readonly>) { +// const createRule = ESLintUtils.RuleCreator( +// ruleName => +// `https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/${ruleName}.md` +// ) +// +// return createRule(rule) as unknown as Rule.RuleModule +// } +export const createEslintRule = ESLintUtils.RuleCreator(name => `https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/${name}.md`) export const joinNames = (a: string | null, b: string | null): string | null => a && b ? `${a}.${b}` : null