From b7d0890757f7f2c9c548dcc252d055bbd2c49039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Wed, 30 Oct 2024 17:23:47 +0100 Subject: [PATCH] feat(deps): update to `@typescript-eslint/*` v8 --- .../detect-testing-library-utils.ts | 17 +- lib/create-testing-library-rule/index.ts | 39 +-- lib/index.ts | 2 +- lib/node-utils/index.ts | 1 + lib/rules/index.ts | 16 +- lib/rules/no-manual-cleanup.ts | 1 + lib/utils/file-import.ts | 2 +- lib/utils/types.ts | 38 +- lint-staged.config.js | 2 +- package-lock.json | 329 ++++++++++++------ package.json | 9 +- tests/eslint-remote-tester.config.js | 2 +- tests/index.test.ts | 2 +- tests/lib/FlatCompatRuleTester.ts | 81 ----- tests/lib/test-utils.ts | 37 +- tools/generate-configs/index.ts | 16 +- tools/generate-configs/utils.ts | 4 +- 17 files changed, 296 insertions(+), 302 deletions(-) delete mode 100644 tests/lib/FlatCompatRuleTester.ts diff --git a/lib/create-testing-library-rule/detect-testing-library-utils.ts b/lib/create-testing-library-rule/detect-testing-library-utils.ts index 11d10ff6..001dc532 100644 --- a/lib/create-testing-library-rule/detect-testing-library-utils.ts +++ b/lib/create-testing-library-rule/detect-testing-library-utils.ts @@ -36,8 +36,8 @@ export type TestingLibrarySettings = { }; export type TestingLibraryContext< - TOptions extends readonly unknown[], TMessageIds extends string, + TOptions extends readonly unknown[], > = Readonly< TSESLint.RuleContext & { settings: TestingLibrarySettings; @@ -45,14 +45,13 @@ export type TestingLibraryContext< >; export type EnhancedRuleCreate< - TOptions extends readonly unknown[], TMessageIds extends string, - TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener, + TOptions extends readonly unknown[], > = ( - context: TestingLibraryContext, + context: TestingLibraryContext, optionsWithDefault: Readonly, detectionHelpers: Readonly -) => TRuleListener; +) => TSESLint.RuleListener; // Helpers methods type GetTestingLibraryImportNodeFn = () => ImportModuleNode | null; @@ -156,15 +155,14 @@ export type DetectionOptions = { * Enhances a given rule `create` with helpers to detect Testing Library utils. */ export function detectTestingLibraryUtils< - TOptions extends readonly unknown[], TMessageIds extends string, - TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener, + TOptions extends readonly unknown[], >( - ruleCreate: EnhancedRuleCreate, + ruleCreate: EnhancedRuleCreate, { skipRuleReportingCheck = false }: Partial = {} ) { return ( - context: TestingLibraryContext, + context: TestingLibraryContext, optionsWithDefault: Readonly ): TSESLint.RuleListener => { const importedTestingLibraryNodes: ImportModuleNode[] = []; @@ -214,6 +212,7 @@ export function detectTestingLibraryUtils< const originalNodeName = isImportSpecifier(importedUtilSpecifier) && + ASTUtils.isIdentifier(importedUtilSpecifier.imported) && importedUtilSpecifier.local.name !== importedUtilSpecifier.imported.name ? importedUtilSpecifier.imported.name : undefined; diff --git a/lib/create-testing-library-rule/index.ts b/lib/create-testing-library-rule/index.ts index 79e5e61e..82e28403 100644 --- a/lib/create-testing-library-rule/index.ts +++ b/lib/create-testing-library-rule/index.ts @@ -1,6 +1,6 @@ -import { ESLintUtils, TSESLint } from '@typescript-eslint/utils'; +import { ESLintUtils } from '@typescript-eslint/utils'; -import { getDocsUrl, TestingLibraryRuleMeta } from '../utils'; +import { getDocsUrl, TestingLibraryPluginDocs } from '../utils'; import { DetectionOptions, @@ -11,32 +11,27 @@ import { export const createTestingLibraryRule = < TOptions extends readonly unknown[], TMessageIds extends string, - TRuleListener extends TSESLint.RuleListener = TSESLint.RuleListener, >({ create, detectionOptions = {}, - meta, ...remainingConfig -}: Readonly<{ - name: string; - meta: TestingLibraryRuleMeta; - defaultOptions: Readonly; - detectionOptions?: Partial; - create: EnhancedRuleCreate; -}>): TSESLint.RuleModule => - ESLintUtils.RuleCreator(getDocsUrl)({ +}: Readonly< + Omit< + ESLintUtils.RuleWithMetaAndName< + TOptions, + TMessageIds, + TestingLibraryPluginDocs + >, + 'create' + > & { + create: EnhancedRuleCreate; + detectionOptions?: Partial; + } +>) => + ESLintUtils.RuleCreator>(getDocsUrl)({ ...remainingConfig, - create: detectTestingLibraryUtils( + create: detectTestingLibraryUtils( create, detectionOptions ), - meta: { - ...meta, - docs: { - ...meta.docs, - // We're using our own recommendedConfig meta to tell our build tools - // if the rule is recommended on a config basis - recommended: undefined, - }, - }, }); diff --git a/lib/index.ts b/lib/index.ts index fb9c2b88..bb6f4db6 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -8,7 +8,7 @@ import { SupportedTestingFramework } from './utils'; const { name: packageName, version: packageVersion, - // eslint-disable-next-line @typescript-eslint/no-var-requires + // eslint-disable-next-line @typescript-eslint/no-require-imports } = require('../package.json') as { name: string; version: string }; const plugin = { diff --git a/lib/node-utils/index.ts b/lib/node-utils/index.ts index 2dc82873..85714c48 100644 --- a/lib/node-utils/index.ts +++ b/lib/node-utils/index.ts @@ -665,6 +665,7 @@ export function findImportSpecifier( const namedExport = node.specifiers.find((n) => { return ( isImportSpecifier(n) && + ASTUtils.isIdentifier(n.imported) && [n.imported.name, n.local.name].includes(specifierName) ); }); diff --git a/lib/rules/index.ts b/lib/rules/index.ts index 7a340ac0..94dc6754 100644 --- a/lib/rules/index.ts +++ b/lib/rules/index.ts @@ -1,15 +1,7 @@ import { readdirSync } from 'fs'; import { join, parse } from 'path'; -import { TSESLint } from '@typescript-eslint/utils'; - -import { importDefault, TestingLibraryRuleMeta } from '../utils'; - -type RuleModule = TSESLint.RuleModule & { - meta: TestingLibraryRuleMeta & { - recommended: false; - }; -}; +import { importDefault, TestingLibraryPluginRuleModule } from '../utils'; const rulesDir = __dirname; const excludedFiles = ['index']; @@ -17,10 +9,12 @@ const excludedFiles = ['index']; export default readdirSync(rulesDir) .map((rule) => parse(rule).name) .filter((ruleName) => !excludedFiles.includes(ruleName)) - .reduce>( + .reduce>>( (allRules, ruleName) => ({ ...allRules, - [ruleName]: importDefault(join(rulesDir, ruleName)), + [ruleName]: importDefault< + TestingLibraryPluginRuleModule + >(join(rulesDir, ruleName)), }), {} ); diff --git a/lib/rules/no-manual-cleanup.ts b/lib/rules/no-manual-cleanup.ts index ee65ee71..184f23ed 100644 --- a/lib/rules/no-manual-cleanup.ts +++ b/lib/rules/no-manual-cleanup.ts @@ -75,6 +75,7 @@ export default createTestingLibraryRule({ const cleanupSpecifier = moduleNode.specifiers.find( (specifier) => isImportSpecifier(specifier) && + ASTUtils.isIdentifier(specifier.imported) && specifier.imported.name === 'cleanup' ); diff --git a/lib/utils/file-import.ts b/lib/utils/file-import.ts index 6bfeae0f..c4198089 100644 --- a/lib/utils/file-import.ts +++ b/lib/utils/file-import.ts @@ -5,5 +5,5 @@ const interopRequireDefault = (obj: any): { default: T } => obj?.__esModule ? obj : { default: obj }; export const importDefault = (moduleName: string): T => - // eslint-disable-next-line @typescript-eslint/no-var-requires + // eslint-disable-next-line @typescript-eslint/no-require-imports interopRequireDefault(require(moduleName)).default; diff --git a/lib/utils/types.ts b/lib/utils/types.ts index 67337402..6b42fbde 100644 --- a/lib/utils/types.ts +++ b/lib/utils/types.ts @@ -1,30 +1,30 @@ -import { type TSESLint } from '@typescript-eslint/utils'; +import { TSESLint } from '@typescript-eslint/utils'; type Recommended = 'error' | 'warn' | false; type RecommendedConfig = | Recommended | [Recommended, ...TOptions]; -// These 2 types are copied from `@typescript-eslint/utils`' `CreateRuleMeta` -// and modified to our needs -export type TestingLibraryRuleMetaDocs = - Omit, 'recommended' | 'url'> & { - /** - * The recommendation level for the rule on a framework basis. - * Used by the build tools to generate the framework config. - * Set to `false` to not include it the config - */ - recommendedConfig: Record< - SupportedTestingFramework, - RecommendedConfig - >; - }; -export type TestingLibraryRuleMeta< +export type TestingLibraryPluginDocs = { + /** + * The recommendation level for the rule on a framework basis. + * Used by the build tools to generate the framework config. + * Set to `false` to not include it the config + */ + recommendedConfig: Record< + SupportedTestingFramework, + RecommendedConfig + >; +}; + +export type TestingLibraryPluginRuleModule< TMessageIds extends string, TOptions extends readonly unknown[], -> = Omit, 'docs'> & { - docs: TestingLibraryRuleMetaDocs; -}; +> = TSESLint.RuleModuleWithMetaDocs< + TMessageIds, + TOptions, + TestingLibraryPluginDocs +>; export const SUPPORTED_TESTING_FRAMEWORKS = [ 'dom', diff --git a/lint-staged.config.js b/lint-staged.config.js index bbbe515d..cb757928 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,4 @@ -//eslint-disable-next-line @typescript-eslint/no-var-requires +//eslint-disable-next-line @typescript-eslint/no-require-imports const { ESLint } = require('eslint'); const removeIgnoredFiles = async (files) => { diff --git a/package-lock.json b/package-lock.json index cf3d6560..5d31a958 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.0.0-semantically-released", "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "^7.18.0", - "@typescript-eslint/utils": "^7.18.0" + "@typescript-eslint/scope-manager": "^8.15.0", + "@typescript-eslint/utils": "^8.15.0" }, "devDependencies": { "@babel/core": "^7.25.8", @@ -22,8 +22,9 @@ "@swc/jest": "^0.2.36", "@types/jest": "^27.5.2", "@types/node": "^20.16.12", - "@typescript-eslint/eslint-plugin": "^7.18.0", - "@typescript-eslint/parser": "^7.18.0", + "@typescript-eslint/eslint-plugin": "^8.15.0", + "@typescript-eslint/parser": "^8.15.0", + "@typescript-eslint/rule-tester": "^8.15.0", "del-cli": "^5.1.0", "eslint": "^8.57.1", "eslint-config-prettier": "^9.1.0", @@ -3639,32 +3640,32 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz", - "integrity": "sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.15.0.tgz", + "integrity": "sha512-+zkm9AR1Ds9uLWN3fkoeXgFppaQ+uEVtfOV62dDmsy9QCNqlRHWNEck4yarvRNrvRcHQLGfqBNui3cimoz8XAg==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/type-utils": "7.18.0", - "@typescript-eslint/utils": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", + "@typescript-eslint/scope-manager": "8.15.0", + "@typescript-eslint/type-utils": "8.15.0", + "@typescript-eslint/utils": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^7.0.0", - "eslint": "^8.56.0" + "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -3673,27 +3674,27 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.18.0.tgz", - "integrity": "sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.15.0.tgz", + "integrity": "sha512-7n59qFpghG4uazrF9qtGKBZXn7Oz4sOMm8dwNWDQY96Xlm2oX67eipqcblDj+oY1lLCbf1oltMZFpUso66Kl1A==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/typescript-estree": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", + "@typescript-eslint/scope-manager": "8.15.0", + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/typescript-estree": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0", "debug": "^4.3.4" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -3701,17 +3702,66 @@ } } }, + "node_modules/@typescript-eslint/rule-tester": { + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/rule-tester/-/rule-tester-8.15.0.tgz", + "integrity": "sha512-G9lQX5jX64wrP5nI1nAEBj48dgyYFH8f0pjruQD9byK0Ln2cOyZPMt51rnzsm5ru8Nc7exV5SYyRppEhzaqSfg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/typescript-estree": "8.15.0", + "@typescript-eslint/utils": "8.15.0", + "ajv": "^6.12.6", + "json-stable-stringify-without-jsonify": "^1.0.1", + "lodash.merge": "4.6.2", + "semver": "^7.6.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0" + } + }, + "node_modules/@typescript-eslint/rule-tester/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@typescript-eslint/rule-tester/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz", - "integrity": "sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.15.0.tgz", + "integrity": "sha512-QRGy8ADi4J7ii95xz4UoiymmmMd/zuy9azCaamnZ3FM8T5fZcex8UfJcjkiEZjJSztKfEBe3dZ5T/5RHAmw2mA==", "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0" + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -3719,26 +3769,26 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz", - "integrity": "sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.15.0.tgz", + "integrity": "sha512-UU6uwXDoI3JGSXmcdnP5d8Fffa2KayOhUUqr/AiBnG1Gl7+7ut/oyagVeSkh7bxQ0zSXV9ptRh/4N15nkCqnpw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "7.18.0", - "@typescript-eslint/utils": "7.18.0", + "@typescript-eslint/typescript-estree": "8.15.0", + "@typescript-eslint/utils": "8.15.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -3747,12 +3797,12 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.18.0.tgz", - "integrity": "sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.15.0.tgz", + "integrity": "sha512-n3Gt8Y/KyJNe0S3yDCD2RVKrHBC4gTUcLTebVBXacPy091E6tNspFLKRXlk3hwT4G55nfr1n2AdFqi/XMxzmPQ==", "license": "MIT", "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -3760,22 +3810,22 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz", - "integrity": "sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.15.0.tgz", + "integrity": "sha512-1eMp2JgNec/niZsR7ioFBlsh/Fk0oJbhaqO0jRyQBMgkz7RrFfkqF9lYYmBoGBaSiLnu8TAPQTwoTUiSTUW9dg==", "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0", "debug": "^4.3.4", - "globby": "^11.1.0", + "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -3812,38 +3862,43 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.18.0.tgz", - "integrity": "sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.15.0.tgz", + "integrity": "sha512-k82RI9yGhr0QM3Dnq+egEpz9qB6Un+WLYhmoNcvl8ltMEededhh7otBVVIDDsEEttauwdY/hQoSsOv13lxrFzQ==", "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/typescript-estree": "7.18.0" + "@typescript-eslint/scope-manager": "8.15.0", + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/typescript-estree": "8.15.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" + "eslint": "^8.57.0 || ^9.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz", - "integrity": "sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.15.0.tgz", + "integrity": "sha512-h8vYOulWec9LhpwfAdZf2bjr8xIp0KNKnpgqSz0qqYYKAW/QZKw3ktRndbiAtUz4acH4QLQavwZBYCc0wulA/Q==", "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.18.0", - "eslint-visitor-keys": "^3.4.3" + "@typescript-eslint/types": "8.15.0", + "eslint-visitor-keys": "^4.2.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -3851,12 +3906,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys/node_modules/eslint-visitor-keys": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", - "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", "license": "Apache-2.0", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -4083,6 +4138,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, "engines": { "node": ">=8" } @@ -5472,6 +5528,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, "dependencies": { "path-type": "^4.0.0" }, @@ -7316,6 +7373,7 @@ "version": "11.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", @@ -7335,6 +7393,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true, "engines": { "node": ">=8" } @@ -15321,6 +15380,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, "engines": { "node": ">=8" } @@ -20502,16 +20562,16 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz", - "integrity": "sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.15.0.tgz", + "integrity": "sha512-+zkm9AR1Ds9uLWN3fkoeXgFppaQ+uEVtfOV62dDmsy9QCNqlRHWNEck4yarvRNrvRcHQLGfqBNui3cimoz8XAg==", "dev": true, "requires": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/type-utils": "7.18.0", - "@typescript-eslint/utils": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", + "@typescript-eslint/scope-manager": "8.15.0", + "@typescript-eslint/type-utils": "8.15.0", + "@typescript-eslint/utils": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -20519,53 +20579,87 @@ } }, "@typescript-eslint/parser": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.18.0.tgz", - "integrity": "sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.15.0.tgz", + "integrity": "sha512-7n59qFpghG4uazrF9qtGKBZXn7Oz4sOMm8dwNWDQY96Xlm2oX67eipqcblDj+oY1lLCbf1oltMZFpUso66Kl1A==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/typescript-estree": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", + "@typescript-eslint/scope-manager": "8.15.0", + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/typescript-estree": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0", "debug": "^4.3.4" } }, + "@typescript-eslint/rule-tester": { + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/rule-tester/-/rule-tester-8.15.0.tgz", + "integrity": "sha512-G9lQX5jX64wrP5nI1nAEBj48dgyYFH8f0pjruQD9byK0Ln2cOyZPMt51rnzsm5ru8Nc7exV5SYyRppEhzaqSfg==", + "dev": true, + "requires": { + "@typescript-eslint/typescript-estree": "8.15.0", + "@typescript-eslint/utils": "8.15.0", + "ajv": "^6.12.6", + "json-stable-stringify-without-jsonify": "^1.0.1", + "lodash.merge": "4.6.2", + "semver": "^7.6.0" + }, + "dependencies": { + "ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + } + } + }, "@typescript-eslint/scope-manager": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.18.0.tgz", - "integrity": "sha512-jjhdIE/FPF2B7Z1uzc6i3oWKbGcHb87Qw7AWj6jmEqNOfDFbJWtjt/XfwCpvNkpGWlcJaog5vTR+VV8+w9JflA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.15.0.tgz", + "integrity": "sha512-QRGy8ADi4J7ii95xz4UoiymmmMd/zuy9azCaamnZ3FM8T5fZcex8UfJcjkiEZjJSztKfEBe3dZ5T/5RHAmw2mA==", "requires": { - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0" + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0" } }, "@typescript-eslint/type-utils": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz", - "integrity": "sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.15.0.tgz", + "integrity": "sha512-UU6uwXDoI3JGSXmcdnP5d8Fffa2KayOhUUqr/AiBnG1Gl7+7ut/oyagVeSkh7bxQ0zSXV9ptRh/4N15nkCqnpw==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "7.18.0", - "@typescript-eslint/utils": "7.18.0", + "@typescript-eslint/typescript-estree": "8.15.0", + "@typescript-eslint/utils": "8.15.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" } }, "@typescript-eslint/types": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.18.0.tgz", - "integrity": "sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ==" + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.15.0.tgz", + "integrity": "sha512-n3Gt8Y/KyJNe0S3yDCD2RVKrHBC4gTUcLTebVBXacPy091E6tNspFLKRXlk3hwT4G55nfr1n2AdFqi/XMxzmPQ==" }, "@typescript-eslint/typescript-estree": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.18.0.tgz", - "integrity": "sha512-aP1v/BSPnnyhMHts8cf1qQ6Q1IFwwRvAQGRvBFkWlo3/lH29OXA3Pts+c10nxRxIBrDnoMqzhgdwVe5f2D6OzA==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.15.0.tgz", + "integrity": "sha512-1eMp2JgNec/niZsR7ioFBlsh/Fk0oJbhaqO0jRyQBMgkz7RrFfkqF9lYYmBoGBaSiLnu8TAPQTwoTUiSTUW9dg==", "requires": { - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/visitor-keys": "7.18.0", + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/visitor-keys": "8.15.0", "debug": "^4.3.4", - "globby": "^11.1.0", + "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", @@ -20591,29 +20685,29 @@ } }, "@typescript-eslint/utils": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.18.0.tgz", - "integrity": "sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.15.0.tgz", + "integrity": "sha512-k82RI9yGhr0QM3Dnq+egEpz9qB6Un+WLYhmoNcvl8ltMEededhh7otBVVIDDsEEttauwdY/hQoSsOv13lxrFzQ==", "requires": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.18.0", - "@typescript-eslint/types": "7.18.0", - "@typescript-eslint/typescript-estree": "7.18.0" + "@typescript-eslint/scope-manager": "8.15.0", + "@typescript-eslint/types": "8.15.0", + "@typescript-eslint/typescript-estree": "8.15.0" } }, "@typescript-eslint/visitor-keys": { - "version": "7.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz", - "integrity": "sha512-cDF0/Gf81QpY3xYyJKDV14Zwdmid5+uuENhjH2EqFaF0ni+yAyq/LzMaIJdhNJXZI7uLzwIlA+V7oWoyn6Curg==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.15.0.tgz", + "integrity": "sha512-h8vYOulWec9LhpwfAdZf2bjr8xIp0KNKnpgqSz0qqYYKAW/QZKw3ktRndbiAtUz4acH4QLQavwZBYCc0wulA/Q==", "requires": { - "@typescript-eslint/types": "7.18.0", - "eslint-visitor-keys": "^3.4.3" + "@typescript-eslint/types": "8.15.0", + "eslint-visitor-keys": "^4.2.0" }, "dependencies": { "eslint-visitor-keys": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", - "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==" + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==" } } }, @@ -20778,7 +20872,8 @@ "array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==" + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true }, "array.prototype.findlastindex": { "version": "1.2.5", @@ -21738,6 +21833,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, "requires": { "path-type": "^4.0.0" } @@ -23050,6 +23146,7 @@ "version": "11.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, "requires": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", @@ -23062,7 +23159,8 @@ "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==" + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true } } }, @@ -28807,7 +28905,8 @@ "path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==" + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true }, "picocolors": { "version": "1.1.1", diff --git a/package.json b/package.json index 9e255662..a3abdacd 100644 --- a/package.json +++ b/package.json @@ -51,8 +51,8 @@ "type-check": "tsc --noEmit" }, "dependencies": { - "@typescript-eslint/scope-manager": "^7.18.0", - "@typescript-eslint/utils": "^7.18.0" + "@typescript-eslint/scope-manager": "^8.15.0", + "@typescript-eslint/utils": "^8.15.0" }, "devDependencies": { "@babel/core": "^7.25.8", @@ -64,8 +64,9 @@ "@swc/jest": "^0.2.36", "@types/jest": "^27.5.2", "@types/node": "^20.16.12", - "@typescript-eslint/eslint-plugin": "^7.18.0", - "@typescript-eslint/parser": "^7.18.0", + "@typescript-eslint/eslint-plugin": "^8.15.0", + "@typescript-eslint/parser": "^8.15.0", + "@typescript-eslint/rule-tester": "^8.15.0", "del-cli": "^5.1.0", "eslint": "^8.57.1", "eslint-config-prettier": "^9.1.0", diff --git a/tests/eslint-remote-tester.config.js b/tests/eslint-remote-tester.config.js index 730b5579..f7c63992 100644 --- a/tests/eslint-remote-tester.config.js +++ b/tests/eslint-remote-tester.config.js @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable @typescript-eslint/no-require-imports */ /* eslint-disable import/no-extraneous-dependencies */ const { rules } = require('eslint-plugin-testing-library'); const { diff --git a/tests/index.test.ts b/tests/index.test.ts index 68cfb521..d6dc83eb 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -72,7 +72,7 @@ it('should export configs that refer to actual rules', () => { expect(rule.startsWith(ruleNamePrefix)).toBe(true); expect(ruleNames).toContain(ruleName); - // eslint-disable-next-line @typescript-eslint/no-unsafe-return + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports expect(() => require(`../lib/rules/${ruleName}`)).not.toThrow(); }); }); diff --git a/tests/lib/FlatCompatRuleTester.ts b/tests/lib/FlatCompatRuleTester.ts deleted file mode 100644 index f1d7717e..00000000 --- a/tests/lib/FlatCompatRuleTester.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { TSESLint } from '@typescript-eslint/utils'; -import { version as eslintVersion } from 'eslint/package.json'; -import * as semver from 'semver'; - -export const usingFlatConfig = semver.major(eslintVersion) >= 9; - -export class FlatCompatRuleTester extends TSESLint.RuleTester { - public constructor(testerConfig?: TSESLint.RuleTesterConfig) { - super(FlatCompatRuleTester._flatCompat(testerConfig)); - } - - public override run< - TMessageIds extends string, - TOptions extends readonly unknown[], - >( - ruleName: string, - rule: TSESLint.RuleModule, - tests: TSESLint.RunTests - ) { - super.run(ruleName, rule, { - valid: tests.valid.map((t) => FlatCompatRuleTester._flatCompat(t)), - invalid: tests.invalid.map((t) => FlatCompatRuleTester._flatCompat(t)), - }); - } - - /* istanbul ignore next */ - private static _flatCompat< - T extends - | undefined - | TSESLint.RuleTesterConfig - | string - | TSESLint.ValidTestCase - | TSESLint.InvalidTestCase, - >(config: T): T { - if (!config || !usingFlatConfig || typeof config === 'string') { - return config; - } - - const obj: TSESLint.FlatConfig.Config & { - languageOptions: TSESLint.FlatConfig.LanguageOptions & { - parserOptions: TSESLint.FlatConfig.ParserOptions; - }; - } = { - languageOptions: { parserOptions: {} }, - }; - - for (const [key, value] of Object.entries(config)) { - if (key === 'parser') { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - obj.languageOptions.parser = require(value as string); - - continue; - } - - if (key === 'parserOptions') { - for (const [option, val] of Object.entries( - value as { [s: string]: unknown } - )) { - if (option === 'ecmaVersion' || option === 'sourceType') { - // @ts-expect-error: TS thinks the value could the opposite type of whatever option is - obj.languageOptions[option] = - val as TSESLint.FlatConfig.LanguageOptions[ - | 'ecmaVersion' - | 'sourceType']; - - continue; - } - - obj.languageOptions.parserOptions[option] = val; - } - - continue; - } - - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - obj[key as keyof typeof obj] = value; - } - - return obj as unknown as T; - } -} diff --git a/tests/lib/test-utils.ts b/tests/lib/test-utils.ts index 1b44b9dc..c65ac6c1 100644 --- a/tests/lib/test-utils.ts +++ b/tests/lib/test-utils.ts @@ -1,21 +1,18 @@ -import { resolve } from 'path'; +import tsESLintParser from '@typescript-eslint/parser'; +import { RuleTester, RunTests } from '@typescript-eslint/rule-tester'; -import { TSESLint } from '@typescript-eslint/utils'; - -import { FlatCompatRuleTester } from './FlatCompatRuleTester'; +import { TestingLibraryPluginRuleModule } from '../../lib/utils'; const DEFAULT_TEST_CASE_CONFIG = { filename: 'MyComponent.test.js', }; -class TestingLibraryRuleTester extends FlatCompatRuleTester { - run>( +class TestingLibraryRuleTester extends RuleTester { + run( ruleName: string, - rule: TSESLint.RuleModule, - tests: TSESLint.RunTests + rule: TestingLibraryPluginRuleModule, + { invalid, valid }: RunTests ): void { - const { valid, invalid } = tests; - const finalValid = valid.map((testCase) => { if (typeof testCase === 'string') { return { @@ -35,18 +32,14 @@ class TestingLibraryRuleTester extends FlatCompatRuleTester { } } -export const createRuleTester = ( - parserOptions: Partial = {} -): TSESLint.RuleTester => { - return new TestingLibraryRuleTester({ - parser: resolve('./node_modules/@typescript-eslint/parser/dist'), - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module', - ecmaFeatures: { - jsx: true, +export const createRuleTester = () => + new TestingLibraryRuleTester({ + languageOptions: { + parser: tsESLintParser, + parserOptions: { + ecmaFeatures: { + jsx: true, + }, }, - ...parserOptions, }, }); -}; diff --git a/tools/generate-configs/index.ts b/tools/generate-configs/index.ts index ac439674..db460548 100644 --- a/tools/generate-configs/index.ts +++ b/tools/generate-configs/index.ts @@ -4,24 +4,18 @@ import rules from '../../lib/rules'; import { SUPPORTED_TESTING_FRAMEWORKS, SupportedTestingFramework, + TestingLibraryPluginRuleModule, } from '../../lib/utils'; -import { LinterConfig, writeConfig } from './utils'; +import { writeConfig } from './utils'; const RULE_NAME_PREFIX = 'testing-library/'; const getRecommendedRulesForTestingFramework = ( framework: SupportedTestingFramework ): Record => - Object.entries(rules) - .filter( - ([ - _, - { - meta: { docs }, - }, - ]) => Boolean(docs.recommendedConfig[framework]) - ) + Object.entries>(rules) + .filter(([_, { meta }]) => Boolean(meta.docs.recommendedConfig[framework])) .reduce((allRules, [ruleName, { meta }]) => { const name = `${RULE_NAME_PREFIX}${ruleName}`; const recommendation = meta.docs.recommendedConfig[framework]; @@ -34,7 +28,7 @@ const getRecommendedRulesForTestingFramework = ( (async () => { for (const framework of SUPPORTED_TESTING_FRAMEWORKS) { - const specificFrameworkConfig: LinterConfig = { + const specificFrameworkConfig: TSESLint.Linter.ConfigType = { plugins: ['testing-library'], rules: getRecommendedRulesForTestingFramework(framework), }; diff --git a/tools/generate-configs/utils.ts b/tools/generate-configs/utils.ts index 9e979151..b6f36a39 100644 --- a/tools/generate-configs/utils.ts +++ b/tools/generate-configs/utils.ts @@ -6,8 +6,6 @@ import { format, resolveConfig } from 'prettier'; const prettierConfig = resolveConfig(__dirname); -export type LinterConfig = TSESLint.Linter.Config; - const addAutoGeneratedComment = (code: string) => [ '// THIS CODE WAS AUTOMATICALLY GENERATED', @@ -21,7 +19,7 @@ const addAutoGeneratedComment = (code: string) => * Helper function writes configuration. */ export const writeConfig = async ( - config: LinterConfig, + config: TSESLint.Linter.ConfigType, configName: string ): Promise => { // note: we use `export =` because ESLint will import these configs via a commonjs import