|
1 |
| -import * as eslintPluginGraphQl from '@graphql-eslint/eslint-plugin'; |
2 |
| -import * as eslint from 'eslint'; |
3 |
| -import * as eslintPluginDeprecation from 'eslint-plugin-deprecation'; |
4 |
| -// @ts-expect-error |
5 |
| -import eslintPluginEslintComments from 'eslint-plugin-eslint-comments'; |
6 |
| -// @ts-expect-error |
7 |
| -import * as eslintPluginImport from 'eslint-plugin-import'; |
8 |
| -// @ts-expect-error |
9 |
| -import eslintPluginJSDoc from 'eslint-plugin-jsdoc'; |
10 |
| -import eslintPluginJsonc from 'eslint-plugin-jsonc'; |
11 |
| -import * as eslintPluginMdx from 'eslint-plugin-mdx'; |
12 |
| -// @ts-expect-error |
13 |
| -import eslintPluginPromise from 'eslint-plugin-promise'; |
14 |
| -// @ts-expect-error |
15 |
| -import eslintPluginNode from 'eslint-plugin-node'; |
16 |
| -// @ts-expect-error |
17 |
| -import eslintPluginN from 'eslint-plugin-n'; |
18 |
| -import * as eslintPluginSonarJS from 'eslint-plugin-sonarjs'; |
19 |
| -// @ts-expect-error |
20 |
| -import eslintPluginSpellcheck from 'eslint-plugin-spellcheck'; |
21 |
| -// @ts-expect-error |
22 |
| -import eslintPluginUnicorn from 'eslint-plugin-unicorn'; |
23 |
| -// @ts-expect-error |
24 |
| -import eslintPluginVue from 'eslint-plugin-vue'; |
25 |
| -// @ts-expect-error |
26 |
| -import eslintPluginVuePug from 'eslint-plugin-vue-pug'; |
27 |
| -// @ts-expect-error |
28 |
| -import eslintPluginVueI18n from '@intlify/eslint-plugin-vue-i18n'; |
29 |
| -import eslintPluginTypeScript from '@typescript-eslint/eslint-plugin'; |
30 |
| -import type { Plugin } from '../contracts'; |
| 1 | +import type { Plugin, PluginRules } from '../contracts'; |
31 | 2 |
|
32 | 3 | /**
|
33 | 4 | * Map of plugins for which the script will generate rule files.
|
34 | 5 | */
|
35 | 6 | export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
|
36 | 7 | deprecation: {
|
37 | 8 | name: 'Deprecation',
|
38 |
| - rules: |
39 |
| - // @ts-expect-error: throw error when plugin successfully updated their type defs |
40 |
| - eslintPluginDeprecation.rules as Plugin['rules'], |
| 9 | + module: 'eslint-plugin-deprecation', |
41 | 10 | },
|
42 | 11 | eslint: {
|
43 | 12 | name: 'Eslint',
|
44 |
| - rules: Object.fromEntries(new eslint.Linter().getRules().entries()), |
| 13 | + module: 'eslint', |
45 | 14 | },
|
46 | 15 | 'typescript-eslint': {
|
47 | 16 | name: 'TypeScript',
|
48 | 17 | prefix: '@typescript-eslint',
|
49 |
| - rules: (eslintPluginTypeScript as unknown as Plugin).rules, |
| 18 | + module: '@typescript-eslint/eslint-plugin', |
50 | 19 | },
|
51 | 20 | import: {
|
52 | 21 | name: 'Import',
|
53 |
| - rules: (eslintPluginImport as Plugin).rules, |
| 22 | + module: 'eslint-plugin-import', |
54 | 23 | },
|
55 | 24 | 'eslint-comments': {
|
56 | 25 | name: 'EslintComments',
|
57 |
| - rules: (eslintPluginEslintComments as Plugin).rules, |
| 26 | + module: 'eslint-plugin-eslint-comments', |
58 | 27 | },
|
59 | 28 | 'graphql-eslint': {
|
60 | 29 | name: 'GraphQL',
|
61 | 30 | prefix: '@graphql-eslint',
|
62 |
| - rules: eslintPluginGraphQl.rules as Plugin['rules'], |
| 31 | + module: '@graphql-eslint/eslint-plugin', |
63 | 32 | },
|
64 | 33 | jsdoc: {
|
65 | 34 | name: 'JSDoc',
|
66 | 35 | prefix: 'jsdoc',
|
67 |
| - rules: (eslintPluginJSDoc as Plugin).rules, |
| 36 | + module: 'eslint-plugin-jsdoc', |
68 | 37 | },
|
69 | 38 | jsonc: {
|
70 | 39 | name: 'Jsonc',
|
71 |
| - rules: |
72 |
| - // @ts-expect-error: throw error when plugin successfully updated their type defs |
73 |
| - eslintPluginJsonc.rules as Plugin['rules'], |
| 40 | + module: 'eslint-plugin-jsonc', |
74 | 41 | },
|
75 | 42 | mdx: {
|
76 | 43 | name: 'Mdx',
|
77 |
| - rules: eslintPluginMdx.rules, |
| 44 | + module: 'eslint-plugin-mdx', |
78 | 45 | },
|
79 | 46 | n: {
|
80 | 47 | name: 'N',
|
81 |
| - rules: (eslintPluginN as Plugin).rules, |
| 48 | + module: 'eslint-plugin-n', |
82 | 49 | },
|
83 | 50 | node: {
|
84 | 51 | name: 'Node',
|
85 |
| - rules: (eslintPluginNode as Plugin).rules, |
| 52 | + module: 'eslint-plugin-node', |
86 | 53 | },
|
87 | 54 | promise: {
|
88 | 55 | name: 'Promise',
|
89 |
| - rules: (eslintPluginPromise as Plugin).rules, |
| 56 | + module: 'eslint-plugin-promise', |
90 | 57 | },
|
91 | 58 | sonarjs: {
|
92 | 59 | name: 'SonarJS',
|
93 | 60 | prefix: 'sonarjs',
|
94 |
| - rules: eslintPluginSonarJS.rules, |
| 61 | + module: 'eslint-plugin-sonarjs', |
95 | 62 | },
|
96 | 63 | spellcheck: {
|
97 | 64 | name: 'Spellcheck',
|
98 |
| - rules: (eslintPluginSpellcheck as Plugin).rules, |
| 65 | + module: 'eslint-plugin-spellcheck', |
99 | 66 | },
|
100 | 67 | unicorn: {
|
101 | 68 | name: 'Unicorn',
|
102 |
| - rules: (eslintPluginUnicorn as Plugin).rules, |
| 69 | + module: 'eslint-plugin-unicorn', |
103 | 70 | },
|
104 | 71 | vue: {
|
105 | 72 | name: 'Vue',
|
106 |
| - rules: (eslintPluginVue as Plugin).rules, |
| 73 | + module: 'eslint-plugin-vue', |
107 | 74 | },
|
108 | 75 | 'vue-i18n': {
|
109 | 76 | name: 'VueI18n',
|
110 | 77 | prefix: '@intlify/vue-i18n',
|
111 |
| - rules: (eslintPluginVueI18n as Plugin).rules, |
| 78 | + module: '@intlify/eslint-plugin-vue-i18n', |
112 | 79 | },
|
113 | 80 | 'vue-pug': {
|
114 | 81 | name: 'VuePug',
|
115 |
| - rules: (eslintPluginVuePug as Plugin).rules, |
| 82 | + module: 'eslint-plugin-vue-pug', |
116 | 83 | },
|
117 | 84 | } as const;
|
| 85 | + |
| 86 | +export async function loadPlugin(plugin: Plugin): Promise<Plugin> { |
| 87 | + const mod: any = await import(plugin.module); |
| 88 | + const rules: PluginRules = |
| 89 | + plugin.module === 'eslint' |
| 90 | + ? Object.fromEntries( |
| 91 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access |
| 92 | + new mod.Linter().getRules().entries(), |
| 93 | + ) |
| 94 | + : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
| 95 | + mod.rules ?? mod.default.rules; |
| 96 | + return { ...plugin, rules }; |
| 97 | +} |
0 commit comments