diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index 855888fd28..5f7931fc59 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,6 +1,6 @@ import process from 'node:process' +import { GLOB_SRC, GLOB_TS, GLOB_TSX } from '../globs' import type { FlatConfigItem, OptionsComponentExts, OptionsFiles, OptionsOverrides, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes } from '../types' -import { GLOB_SRC } from '../globs' import { pluginAntfu } from '../plugins' import { interopDefault, renameRules, toArray } from '../utils' @@ -18,6 +18,8 @@ export async function typescript( ...componentExts.map(ext => `**/*.${ext}`), ] + const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX] + const typeAwareRules: FlatConfigItem['rules'] = { 'dot-notation': 'off', 'no-implied-eval': 'off', @@ -89,7 +91,6 @@ export async function typescript( '@typescript-eslint/', 'ts/', ), - 'no-dupe-class-members': 'off', 'no-loss-of-precision': 'off', 'no-redeclare': 'off', @@ -115,7 +116,13 @@ export async function typescript( 'ts/prefer-ts-expect-error': 'error', 'ts/triple-slash-reference': 'off', 'ts/unified-signatures': 'off', - + ...overrides, + }, + }, + { + files: filesTypeAware, + name: 'antfu:typescript:rules-type-aware', + rules: { ...tsconfigPath ? typeAwareRules : {}, ...overrides, }, diff --git a/src/types.ts b/src/types.ts index db7b000568..8c556145e5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -156,6 +156,12 @@ export interface OptionsTypeScriptParserOptions { * Additional parser options for TypeScript. */ parserOptions?: Partial + + /** + * Glob patterns for files that should be type aware. + * @default ['**\/*.{ts,tsx}'] + */ + filesTypeAware?: string[] } export interface OptionsTypeScriptWithTypes {