Skip to content

Commit

Permalink
chore: assign plugins to configs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Belco90 committed Apr 27, 2024
1 parent 5307539 commit 4e1b524
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/index.ts
Expand Up @@ -2,7 +2,9 @@ import packageMetadata from '../package.json';

import configs from './configs';
import rules from './rules';
import { type SupportedTestingFramework } from './utils';

// TODO: type properly when upgraded to ESLint v9
const plugin = {
meta: {
name: packageMetadata.name,
Expand All @@ -13,12 +15,13 @@ const plugin = {
};

// TODO: type this with TSESLint.Linter.RuleEntry when upgraded to ESLint v9
const pluginConfigs: Record<string, unknown> = {};
for (const [key, config] of Object.entries(configs)) {
pluginConfigs[key] = {
...config,
plugins: { 'testing-library': plugin },
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 default plugin;
6 changes: 6 additions & 0 deletions tests/index.test.ts
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

0 comments on commit 4e1b524

Please sign in to comment.