Skip to content

Commit

Permalink
feat: typescript.tsconfigPath array support (#306)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
rost-git and antfu committed Oct 31, 2023
1 parent 52b4fe5 commit 546526a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/configs/typescript.ts
Expand Up @@ -2,7 +2,7 @@ import process from 'node:process'
import type { ConfigItem, OptionsComponentExts, OptionsOverrides, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes } from '../types'
import { GLOB_SRC } from '../globs'
import { parserTs, pluginAntfu, pluginImport, pluginTs } from '../plugins'
import { renameRules } from '../utils'
import { renameRules, toArray } from '../utils'

export function typescript(
options?: OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions,
Expand All @@ -11,7 +11,6 @@ export function typescript(
componentExts = [],
overrides = {},
parserOptions = {},
tsconfigPath,
} = options ?? {}

const typeAwareRules: ConfigItem['rules'] = {
Expand All @@ -36,6 +35,10 @@ export function typescript(
'ts/unbound-method': 'error',
}

const tsconfigPath = options?.tsconfigPath
? toArray(options.tsconfigPath)
: undefined

return [
{
// Install the plugins without globs, so they can be configured separately.
Expand All @@ -58,7 +61,7 @@ export function typescript(
sourceType: 'module',
...tsconfigPath
? {
project: [tsconfigPath],
project: tsconfigPath,
tsconfigRootDir: process.cwd(),
}
: {},
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -86,7 +86,7 @@ export interface OptionsTypeScriptWithTypes {
* When this options is provided, type aware rules will be enabled.
* @see https://typescript-eslint.io/linting/typed-linting/
*/
tsconfigPath?: string
tsconfigPath?: string | string[]
}

export interface OptionsHasTypeScript {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Expand Up @@ -17,3 +17,7 @@ export function renameRules(rules: Record<string, any>, from: string, to: string
}),
)
}

export function toArray<T>(value: T | T[]): T[] {
return Array.isArray(value) ? value : [value]
}

0 comments on commit 546526a

Please sign in to comment.