|
| 1 | +// Type tests for the root `index.d.ts` (see #3169). |
| 2 | +// Compiled by `npm run test-types` via `tests/types/tsconfig.json`; |
| 3 | +// never executed at runtime. |
| 4 | + |
| 5 | +import importPlugin from 'eslint-plugin-import'; |
| 6 | +import { ESLint, Linter, Rule } from 'eslint'; |
| 7 | + |
| 8 | +type IsAny<T> = 0 extends 1 & T ? true : false; |
| 9 | + |
| 10 | +// the plugin object itself is a usable, fully-typed ESLint plugin |
| 11 | +const plugin: ESLint.Plugin = importPlugin; |
| 12 | + |
| 13 | +// `flatConfigs` and its entries must not be optional or `any` (#3169) |
| 14 | +const flatConfigsNotAny: IsAny<typeof importPlugin.flatConfigs> = false; |
| 15 | +const recommendedNotAny: IsAny<typeof importPlugin.flatConfigs.recommended> = false; |
| 16 | + |
| 17 | +// the README flat-config examples: every flat config is a defined `Linter.FlatConfig` |
| 18 | +const flatConfigs: Linter.FlatConfig[] = [ |
| 19 | + importPlugin.flatConfigs.recommended, |
| 20 | + importPlugin.flatConfigs.errors, |
| 21 | + importPlugin.flatConfigs.warnings, |
| 22 | + importPlugin.flatConfigs.react, |
| 23 | + importPlugin.flatConfigs['react-native'], |
| 24 | + importPlugin.flatConfigs.electron, |
| 25 | + importPlugin.flatConfigs.typescript, |
| 26 | +]; |
| 27 | + |
| 28 | +// @ts-expect-error `stage-0` only exists in the legacy `configs`, not in `flatConfigs` |
| 29 | +importPlugin.flatConfigs['stage-0']; |
| 30 | + |
| 31 | +// the legacy configs are eslintrc-style configs, including `stage-0` |
| 32 | +const legacyConfigs: Linter.LegacyConfig[] = [ |
| 33 | + importPlugin.configs.recommended, |
| 34 | + importPlugin.configs.errors, |
| 35 | + importPlugin.configs.warnings, |
| 36 | + importPlugin.configs['stage-0'], |
| 37 | + importPlugin.configs.react, |
| 38 | + importPlugin.configs['react-native'], |
| 39 | + importPlugin.configs.electron, |
| 40 | + importPlugin.configs.typescript, |
| 41 | +]; |
| 42 | + |
| 43 | +// every rule is a fully-typed rule module |
| 44 | +const orderRule: Rule.RuleModule = importPlugin.rules.order; |
0 commit comments