diff --git a/jest.config.js b/jest.config.js index f546d6ef..61990593 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - testMatch: ['**/tests/**/*.test.ts'], + roots: ['/tests/'], transform: { '^.+\\.ts$': '@swc/jest', }, diff --git a/lib/configs/angular.ts b/lib/configs/angular.ts index 270e4d48..6243b224 100644 --- a/lib/configs/angular.ts +++ b/lib/configs/angular.ts @@ -3,7 +3,6 @@ // YOU CAN REGENERATE IT USING npm run generate:configs export = { - plugins: ['testing-library'], rules: { 'testing-library/await-async-events': [ 'error', diff --git a/lib/configs/dom.ts b/lib/configs/dom.ts index ed568225..6d556a3d 100644 --- a/lib/configs/dom.ts +++ b/lib/configs/dom.ts @@ -3,7 +3,6 @@ // YOU CAN REGENERATE IT USING npm run generate:configs export = { - plugins: ['testing-library'], rules: { 'testing-library/await-async-events': [ 'error', diff --git a/lib/configs/marko.ts b/lib/configs/marko.ts index 066c3498..75de63ca 100644 --- a/lib/configs/marko.ts +++ b/lib/configs/marko.ts @@ -3,7 +3,6 @@ // YOU CAN REGENERATE IT USING npm run generate:configs export = { - plugins: ['testing-library'], rules: { 'testing-library/await-async-events': [ 'error', diff --git a/lib/configs/react.ts b/lib/configs/react.ts index 275a0c3a..5d17f309 100644 --- a/lib/configs/react.ts +++ b/lib/configs/react.ts @@ -3,7 +3,6 @@ // YOU CAN REGENERATE IT USING npm run generate:configs export = { - plugins: ['testing-library'], rules: { 'testing-library/await-async-events': [ 'error', diff --git a/lib/configs/vue.ts b/lib/configs/vue.ts index fdf8bfb7..ed34e7a3 100644 --- a/lib/configs/vue.ts +++ b/lib/configs/vue.ts @@ -3,7 +3,6 @@ // YOU CAN REGENERATE IT USING npm run generate:configs export = { - plugins: ['testing-library'], rules: { 'testing-library/await-async-events': [ 'error', diff --git a/lib/index.ts b/lib/index.ts index c270f91d..7c0c2d87 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,7 +1,30 @@ +import { + name as packageName, + version as packageVersion, +} from '../package.json'; + import configs from './configs'; import rules from './rules'; +import { type SupportedTestingFramework } from './utils'; -export = { +// TODO: type properly when upgraded to ESLint v9 +const plugin = { + meta: { + name: packageName, + version: packageVersion, + }, configs, rules, }; + +// TODO: type this with TSESLint.Linter.RuleEntry when upgraded to ESLint v9 +Object.keys(plugin.configs).forEach((configKey) => { + plugin.configs[configKey as SupportedTestingFramework].plugins = { + // TODO: remove ignored error when properly typed with ESLint v9 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + 'testing-library': plugin, + }; +}); + +export = plugin; diff --git a/package.json b/package.json index 9b0abbc9..93adb393 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "README.md", "LICENSE" ], - "main": "./dist/index.js", + "main": "./dist/lib/index.js", "scripts": { "prebuild": "del-cli dist", "build": "tsc", diff --git a/tests/index.test.ts b/tests/index.test.ts index 6788a479..2ee632cf 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -43,6 +43,12 @@ it('should have the correct amount of rules', () => { } }); +it('should refer to the plugin itself on each config', () => { + Object.entries(plugin.configs).forEach(([_, config]) => { + expect(config.plugins).toEqual({ 'testing-library': plugin }); + }); +}); + it('should export configs that refer to actual rules', () => { const allConfigs = plugin.configs; diff --git a/tools/generate-configs/index.ts b/tools/generate-configs/index.ts index 87c773c2..930cb4ec 100644 --- a/tools/generate-configs/index.ts +++ b/tools/generate-configs/index.ts @@ -33,7 +33,8 @@ const getRecommendedRulesForTestingFramework = ( SUPPORTED_TESTING_FRAMEWORKS.forEach((framework) => { const specificFrameworkConfig: LinterConfig = { - plugins: ['testing-library'], + // "plugins" property must be assigned after defining the plugin variable in the "lib/index.ts" + // https://eslint.org/docs/latest/extend/plugin-migration-flat-config#migrating-configs-for-flat-config rules: getRecommendedRulesForTestingFramework(framework), };