|
1 | 1 | import type { TSESLint } from '@typescript-eslint/utils'
|
2 | 2 |
|
3 |
| -// rules |
| 3 | +import { name, version } from '../package.json' |
| 4 | + |
| 5 | +// legacy configs |
4 | 6 | import electron from './config/electron'
|
5 | 7 | import errors from './config/errors'
|
| 8 | + |
| 9 | +// flat configs |
| 10 | +import electronFlat from './config/flat/electron' |
| 11 | +import errorsFlat from './config/flat/errors' |
| 12 | +import reactFlat from './config/flat/react' |
| 13 | +import reactNativeFlat from './config/flat/react-native' |
| 14 | +import recommendedFlat from './config/flat/recommended' |
| 15 | +import stage0Flat from './config/flat/stage-0' |
| 16 | +import typescriptFlat from './config/flat/typescript' |
| 17 | +import warningsFlat from './config/flat/warnings' |
6 | 18 | import react from './config/react'
|
7 | 19 | import reactNative from './config/react-native'
|
8 | 20 | import recommended from './config/recommended'
|
9 | 21 | import stage0 from './config/stage-0'
|
10 | 22 | import typescript from './config/typescript'
|
11 | 23 | import warnings from './config/warnings'
|
| 24 | + |
| 25 | +// rules |
12 | 26 | import consistentTypeSpecifierStyle from './rules/consistent-type-specifier-style'
|
13 | 27 | import default_ from './rules/default'
|
14 | 28 | import dynamicImportChunkname from './rules/dynamic-import-chunkname'
|
@@ -55,23 +69,11 @@ import order from './rules/order'
|
55 | 69 | import preferDefaultExport from './rules/prefer-default-export'
|
56 | 70 | import unambiguous from './rules/unambiguous'
|
57 | 71 | // configs
|
58 |
| -import type { PluginConfig } from './types' |
59 |
| - |
60 |
| -const configs = { |
61 |
| - recommended, |
62 |
| - |
63 |
| - errors, |
64 |
| - warnings, |
65 |
| - |
66 |
| - // shhhh... work in progress "secret" rules |
67 |
| - 'stage-0': stage0, |
68 |
| - |
69 |
| - // useful stuff for folks using various environments |
70 |
| - react, |
71 |
| - 'react-native': reactNative, |
72 |
| - electron, |
73 |
| - typescript, |
74 |
| -} satisfies Record<string, PluginConfig> |
| 72 | +import type { |
| 73 | + PluginConfig, |
| 74 | + PluginFlatBaseConfig, |
| 75 | + PluginFlatConfig, |
| 76 | +} from './types' |
75 | 77 |
|
76 | 78 | const rules = {
|
77 | 79 | 'no-unresolved': noUnresolved,
|
@@ -129,7 +131,56 @@ const rules = {
|
129 | 131 | 'imports-first': importsFirst,
|
130 | 132 | } satisfies Record<string, TSESLint.RuleModule<string, readonly unknown[]>>
|
131 | 133 |
|
| 134 | +const configs = { |
| 135 | + recommended, |
| 136 | + |
| 137 | + errors, |
| 138 | + warnings, |
| 139 | + |
| 140 | + // shhhh... work in progress "secret" rules |
| 141 | + 'stage-0': stage0, |
| 142 | + |
| 143 | + // useful stuff for folks using various environments |
| 144 | + react, |
| 145 | + 'react-native': reactNative, |
| 146 | + electron, |
| 147 | + typescript, |
| 148 | +} satisfies Record<string, PluginConfig> |
| 149 | + |
| 150 | +// Base Plugin Object |
| 151 | +const plugin = { |
| 152 | + meta: { name, version }, |
| 153 | + rules, |
| 154 | +} |
| 155 | + |
| 156 | +// Create flat configs (Only ones that declare plugins and parser options need to be different from the legacy config) |
| 157 | +const createFlatConfig = ( |
| 158 | + baseConfig: PluginFlatBaseConfig, |
| 159 | + configName: string, |
| 160 | +): PluginFlatConfig => ({ |
| 161 | + ...baseConfig, |
| 162 | + name: `import-x/${configName}`, |
| 163 | + plugins: { 'import-x': plugin }, |
| 164 | +}) |
| 165 | + |
| 166 | +const flatConfigs = { |
| 167 | + recommended: createFlatConfig(recommendedFlat, 'recommended'), |
| 168 | + |
| 169 | + errors: createFlatConfig(errorsFlat, 'errors'), |
| 170 | + warnings: createFlatConfig(warningsFlat, 'warnings'), |
| 171 | + |
| 172 | + // shhhh... work in progress "secret" rules |
| 173 | + 'stage-0': createFlatConfig(stage0Flat, 'stage-0'), |
| 174 | + |
| 175 | + // useful stuff for folks using various environments |
| 176 | + react: reactFlat, |
| 177 | + 'react-native': reactNativeFlat, |
| 178 | + electron: electronFlat, |
| 179 | + typescript: typescriptFlat, |
| 180 | +} satisfies Record<string, PluginFlatConfig> |
| 181 | + |
132 | 182 | export = {
|
133 | 183 | configs,
|
| 184 | + flatConfigs, |
134 | 185 | rules,
|
135 | 186 | }
|
0 commit comments