Skip to content

Commit

Permalink
feat: use typescript project only for type-aware files, closes #380 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimava committed Jan 17, 2024
1 parent 20a1d6d commit 9e2bf16
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/configs/typescript.ts
Expand Up @@ -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',
Expand All @@ -42,10 +46,6 @@ export async function typescript(
'ts/unbound-method': 'error',
}

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

const [
pluginTs,
parserTs,
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

Type 'typeof import("/home/runner/work/eslint-config/eslint-config/node_modules/.pnpm/@typescript-eslint+parser@6.19.0_eslint-ts-patch@8.56.0-0_typescript@5.3.3/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type 'ParserModule | undefined'.

Check failure on line 62 in src/configs/typescript.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, windows-latest)

Type 'typeof import("D:/a/eslint-config/eslint-config/node_modules/.pnpm/@typescript-eslint+parser@6.19.0_eslint-ts-patch@8.56.0-0_typescript@5.3.3/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type 'ParserModule | undefined'.

Check failure on line 62 in src/configs/typescript.ts

View workflow job for this annotation

GitHub Actions / typecheck

Type 'typeof import("/home/runner/work/eslint-config/eslint-config/node_modules/.pnpm/@typescript-eslint+parser@6.19.0_eslint-ts-patch@8.56.0-0_typescript@5.3.3/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type 'ParserModule | undefined'.

Check failure on line 62 in src/configs/typescript.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

Type 'typeof import("/Users/runner/work/eslint-config/eslint-config/node_modules/.pnpm/@typescript-eslint+parser@6.19.0_eslint-ts-patch@8.56.0-0_typescript@5.3.3/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type 'ParserModule | undefined'.
parserOptions: {
extraFileExtensions: componentExts.map(ext => `.${ext}`),
sourceType: 'module',
...tsconfigPath
...typeAware
? {
project: tsconfigPath,
tsconfigRootDir: process.cwd(),
Expand All @@ -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(
Expand Down

0 comments on commit 9e2bf16

Please sign in to comment.