Skip to content

Commit

Permalink
feat(eslint-config): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown committed Nov 3, 2024
1 parent 8af0af9 commit 6f80235
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
11 changes: 5 additions & 6 deletions packages/eslint-config/scripts/generate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const configs = await composer(

const rulesTypeName = 'Rules'
const configNames = configs.map(config => config.name).filter(Boolean) as string[]
const configType = `Linter.Config<Linter.RulesRecord & ${rulesTypeName}>`

let dts = await flatConfigsToRulesDTS(configs, {
exportTypeName: rulesTypeName,
Expand All @@ -54,7 +53,7 @@ import type * as FCUTypes from 'eslint-flat-config-utils'
* Each configuration object contains all of the information ESLint needs to execute on a set of files.
* @see https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects
*/
export type Config = ${configType}
export interface Config<R extends Linter.RulesRecord = Linter.RulesRecord & ${rulesTypeName}> extends Linter.Config<R> {}
/**
* Defines a 'composer' for ESLint flat configurations.
Expand All @@ -64,19 +63,19 @@ export type Config = ${configType}
* @see https://jsr.io/@antfu/eslint-flat-config-utils/doc/~/FlatConfigComposer
*/
export type FlatConfigComposer<
Config extends Linter.Config = ${configType},
C extends Linter.Config = Config,
ConfigNames extends string =
${configNames.length > 0 ? `${configNames.map(name => `'${name}'`).join(' |\n ')}` : 'never'}
> = FCUTypes.FlatConfigComposer<Config, ConfigNames>
> = FCUTypes.FlatConfigComposer<C, ConfigNames>
/**
* Represents a value that resolves to one or more ESLint flat configurations.
* @template Config - The ESLint flat configuration type, extending Linter.Config.
* @see https://jsr.io/@antfu/eslint-flat-config-utils/doc/~/ResolvableFlatConfig
*/
export type ResolvableFlatConfig<
Config extends Linter.Config = ${configType}
> = FCUTypes.ResolvableFlatConfig<Config>
C extends Linter.Config = Config
> = FCUTypes.ResolvableFlatConfig<C>
export type * from './define-config'
Expand Down
56 changes: 28 additions & 28 deletions packages/eslint-config/src/define-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,39 +92,39 @@ export type OptionsTypeScript =
| (OptionsTypeScriptParserOptions & OptionsOverrides)
| (OptionsTypeScriptWithTypes & OptionsOverrides)

type CombinedOptions = {
/**
* Enable gitignore support.
*
* @see https://github.com/antfu/eslint-config-flat-gitignore
* @default true
*/
gitignore?: boolean | FlatGitignoreOptions
type Flatten<T> = T extends object ? {[K in keyof T]: T[K]} : T

isInEditor?: boolean
export type Options = Flatten<
{
/**
* Enable gitignore support.
*
* @see https://github.com/antfu/eslint-config-flat-gitignore
* @default true
*/
gitignore?: boolean | FlatGitignoreOptions

javascript?: OptionsOverrides
isInEditor?: boolean

/**
* Enable support for vitest.
*
* @default false
*/
vitest?: boolean | OptionsOverrides
javascript?: OptionsOverrides

/**
* Enable TypeScript support.
*
* Pass options to enable support for the TypeScript language and project services.
*
* @default auto-detect based on the dependencies
*/
typescript?: OptionsTypeScript | boolean
} & AllowedConfigForOptions
/**
* Enable support for vitest.
*
* @default false
*/
vitest?: boolean | OptionsOverrides

export type Options = {
[K in keyof CombinedOptions]: CombinedOptions[K]
}
/**
* Enable TypeScript support.
*
* Pass options to enable support for the TypeScript language and project services.
*
* @default auto-detect based on the dependencies
*/
typescript?: OptionsTypeScript | boolean
} & Omit<Config, 'files'>
>

/**
* Define a new ESLint config.
Expand Down

0 comments on commit 6f80235

Please sign in to comment.