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