Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ESLint flat config #902

Draft
wants to merge 6 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testMatch: ['**/tests/**/*.test.ts'],
roots: ['<rootDir>/tests/'],
transform: {
'^.+\\.ts$': '@swc/jest',
},
Expand Down
1 change: 0 additions & 1 deletion lib/configs/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// YOU CAN REGENERATE IT USING npm run generate:configs

export = {
plugins: ['testing-library'],
rules: {
'testing-library/await-async-events': [
'error',
Expand Down
1 change: 0 additions & 1 deletion lib/configs/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// YOU CAN REGENERATE IT USING npm run generate:configs

export = {
plugins: ['testing-library'],
rules: {
'testing-library/await-async-events': [
'error',
Expand Down
1 change: 0 additions & 1 deletion lib/configs/marko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// YOU CAN REGENERATE IT USING npm run generate:configs

export = {
plugins: ['testing-library'],
rules: {
'testing-library/await-async-events': [
'error',
Expand Down
1 change: 0 additions & 1 deletion lib/configs/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// YOU CAN REGENERATE IT USING npm run generate:configs

export = {
plugins: ['testing-library'],
rules: {
'testing-library/await-async-events': [
'error',
Expand Down
1 change: 0 additions & 1 deletion lib/configs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// YOU CAN REGENERATE IT USING npm run generate:configs

export = {
plugins: ['testing-library'],
rules: {
'testing-library/await-async-events': [
'error',
Expand Down
25 changes: 24 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"README.md",
"LICENSE"
],
"main": "./dist/index.js",
"main": "./dist/lib/index.js",
"scripts": {
"prebuild": "del-cli dist",
"build": "tsc",
Expand Down
6 changes: 6 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion tools/generate-configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down