-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
30 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ export async function typescript( | |
] | ||
|
||
const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX] | ||
const tsconfigPath = options?.tsconfigPath | ||
? toArray(options.tsconfigPath) | ||
: undefined | ||
const isTypeAware = !!tsconfigPath | ||
|
||
const typeAwareRules: FlatConfigItem['rules'] = { | ||
'dot-notation': 'off', | ||
|
@@ -42,10 +46,6 @@ export async function typescript( | |
'ts/unbound-method': 'error', | ||
} | ||
|
||
const tsconfigPath = options?.tsconfigPath | ||
? toArray(options.tsconfigPath) | ||
: undefined | ||
|
||
const [ | ||
pluginTs, | ||
parserTs, | ||
|
@@ -54,23 +54,16 @@ export async function typescript( | |
interopDefault(import('@typescript-eslint/parser')), | ||
] as const) | ||
|
||
return [ | ||
{ | ||
// Install the plugins without globs, so they can be configured separately. | ||
name: 'antfu:typescript:setup', | ||
plugins: { | ||
antfu: pluginAntfu, | ||
ts: pluginTs as any, | ||
}, | ||
}, | ||
{ | ||
function makeParser(typeAware: boolean, files: string[], ignores?: string[]): FlatConfigItem { | ||
return { | ||
files, | ||
...ignores ? { ignores } : {}, | ||
languageOptions: { | ||
parser: parserTs, | ||
Check failure on line 62 in src/configs/typescript.ts GitHub Actions / test (lts/*, ubuntu-latest)
Check failure on line 62 in src/configs/typescript.ts GitHub Actions / test (lts/*, windows-latest)
Check failure on line 62 in src/configs/typescript.ts GitHub Actions / typecheck
Check failure on line 62 in src/configs/typescript.ts GitHub Actions / test (lts/*, macos-latest)
|
||
parserOptions: { | ||
extraFileExtensions: componentExts.map(ext => `.${ext}`), | ||
sourceType: 'module', | ||
...tsconfigPath | ||
...typeAware | ||
? { | ||
project: tsconfigPath, | ||
tsconfigRootDir: process.cwd(), | ||
|
@@ -79,6 +72,28 @@ export async function typescript( | |
...parserOptions as any, | ||
}, | ||
}, | ||
name: `antfu:typescript:${typeAware ? 'type-aware-parser' : 'parser'}`, | ||
} | ||
} | ||
|
||
return [ | ||
{ | ||
// Install the plugins without globs, so they can be configured separately. | ||
name: 'antfu:typescript:setup', | ||
plugins: { | ||
antfu: pluginAntfu, | ||
ts: pluginTs as any, | ||
}, | ||
}, | ||
// assign type-aware parser for type-aware files and type-unaware parser for the rest | ||
...isTypeAware | ||
? [ | ||
makeParser(true, filesTypeAware), | ||
makeParser(false, files, filesTypeAware), | ||
] | ||
: [makeParser(false, files)], | ||
{ | ||
files, | ||
name: 'antfu:typescript:rules', | ||
rules: { | ||
...renameRules( | ||
|