Skip to content

Commit

Permalink
fix: only apply type-aware on ts files, close #375
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 25, 2023
1 parent f4c9ddf commit 0c1c8db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions 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'

Expand All @@ -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',
Expand Down Expand Up @@ -89,7 +91,6 @@ export async function typescript(
'@typescript-eslint/',
'ts/',
),

'no-dupe-class-members': 'off',
'no-loss-of-precision': 'off',
'no-redeclare': 'off',
Expand All @@ -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,
},
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Expand Up @@ -156,6 +156,12 @@ export interface OptionsTypeScriptParserOptions {
* Additional parser options for TypeScript.
*/
parserOptions?: Partial<ParserOptions>

/**
* Glob patterns for files that should be type aware.
* @default ['**\/*.{ts,tsx}']
*/
filesTypeAware?: string[]
}

export interface OptionsTypeScriptWithTypes {
Expand Down

0 comments on commit 0c1c8db

Please sign in to comment.