|
1 | 1 | declare module '@metamask/eslint-config' {
|
2 | 2 | import type { Linter } from 'eslint';
|
3 | 3 |
|
4 |
| - const config: Linter.Config[]; |
| 4 | + /** |
| 5 | + * An ESLint configuration object. |
| 6 | + */ |
| 7 | + type Config = Linter.Config; |
| 8 | + |
| 9 | + /** |
| 10 | + * An ESLint configuration object that may extend other configurations. This |
| 11 | + * can only be used with the {@link createConfig} function. |
| 12 | + */ |
| 13 | + type ConfigWithExtends = Config & { |
| 14 | + extends?: Config | Config[] | Config[][]; |
| 15 | + }; |
| 16 | + |
| 17 | + /** |
| 18 | + * Create a config object that extends other configs. |
| 19 | + * |
| 20 | + * ESLint 9 removed support for extending arrays of configs, so this function |
| 21 | + * provides a workaround. It takes an array of config objects, where each object |
| 22 | + * may have an `extends` property that is an array of other config objects. |
| 23 | + * |
| 24 | + * This function is inspired by the `config` function in the `typescript-eslint` |
| 25 | + * package, but to avoid a dependency on that package, this function is |
| 26 | + * implemented here. |
| 27 | + * |
| 28 | + * @param configs - An array of config objects. |
| 29 | + * @returns An array of config objects with all `extends` properties |
| 30 | + * resolved. |
| 31 | + * @example Basic usage. |
| 32 | + * import { createConfig } from '@metamask/eslint-config'; |
| 33 | + * import typescript from '@metamask/eslint-config-typescript'; |
| 34 | + * |
| 35 | + * const configs = createConfig([ |
| 36 | + * { |
| 37 | + * files: ['**\/*.ts'], |
| 38 | + * extends: typescript, |
| 39 | + * }, |
| 40 | + * ]); |
| 41 | + * |
| 42 | + * export default configs; |
| 43 | + * |
| 44 | + * @example Multiple extends are supported as well. |
| 45 | + * import { createConfig } from '@metamask/eslint-config'; |
| 46 | + * import typescript from '@metamask/eslint-config-typescript'; |
| 47 | + * import nodejs from '@metamask/eslint-config-nodejs'; |
| 48 | + * |
| 49 | + * const configs = createConfig([ |
| 50 | + * { |
| 51 | + * files: ['**\/*.ts'], |
| 52 | + * extends: [typescript, nodejs], |
| 53 | + * }, |
| 54 | + * ]); |
| 55 | + * |
| 56 | + * export default configs; |
| 57 | + */ |
| 58 | + export function createConfig( |
| 59 | + configs: ConfigWithExtends | ConfigWithExtends[], |
| 60 | + ): Config[]; |
| 61 | + |
| 62 | + const config: Config[]; |
5 | 63 | export default config;
|
6 | 64 | }
|
0 commit comments