1+ import process from 'node:process'
12import * as tseslint from 'typescript-eslint'
2-
3- import type { VueTsPreset } from './configs'
4- import { getConfigForPlaceholder } from './configs'
3+ import { TsEslintConfigForVue } from './configs'
54import groupVueFiles from './groupVueFiles'
65import {
76 additionalRulesRequiringParserServices ,
@@ -10,17 +9,16 @@ import {
109 createTypeCheckingConfigs ,
1110} from './internals'
1211
12+ import type { ScriptLang } from './internals'
13+
1314type ConfigArray = ReturnType < typeof tseslint . config >
1415type Rules = NonNullable < ConfigArray [ number ] [ 'rules' ] >
1516
16- type ConfigOrVueTsPreset = ConfigArray [ number ] | VueTsPreset
17+ type ConfigObjectOrPlaceholder = ConfigArray [ number ] | TsEslintConfigForVue
1718type InfiniteDepthConfigWithVueSupport =
18- | ConfigOrVueTsPreset
19+ | ConfigObjectOrPlaceholder
1920 | InfiniteDepthConfigWithVueSupport [ ]
2021
21- import process from 'node:process'
22- import type { ScriptLang } from './internals'
23-
2422export type ProjectOptions = {
2523 scriptLangs ?: ScriptLang [ ]
2624 rootDir ?: string
@@ -48,11 +46,14 @@ export function configureVueProject(userOptions: ProjectOptions) {
4846export function defineConfigWithVueTs (
4947 ...configs : InfiniteDepthConfigWithVueSupport [ ]
5048) : ConfigArray {
51- // @ts -ignore
52- const flattenedConfigs : Array < ConfigOrVueTsPreset > = configs . flat ( Infinity )
53- const normalizedConfigs = insertAndReorderConfigs ( flattenedConfigs ) . map (
54- config =>
55- typeof config === 'string' ? getConfigForPlaceholder ( config ) : config ,
49+ const flattenedConfigs : Array < ConfigObjectOrPlaceholder > =
50+ // @ts -ignore
51+ configs . flat ( Infinity )
52+
53+ const reorderedConfigs = insertAndReorderConfigs ( flattenedConfigs )
54+
55+ const normalizedConfigs = reorderedConfigs . map ( config =>
56+ config instanceof TsEslintConfigForVue ? config . toConfigArray ( ) : config ,
5657 )
5758
5859 return tseslint . config ( ...normalizedConfigs )
@@ -86,10 +87,10 @@ type ExtractedConfig = {
8687const userTypeAwareConfigs : ExtractedConfig [ ] = [ ]
8788
8889function insertAndReorderConfigs (
89- configs : Array < ConfigOrVueTsPreset > ,
90- ) : Array < ConfigOrVueTsPreset > {
90+ configs : Array < ConfigObjectOrPlaceholder > ,
91+ ) : Array < ConfigObjectOrPlaceholder > {
9192 const lastExtendedConfigIndex = configs . findLastIndex (
92- config => typeof config === 'string' ,
93+ config => config instanceof TsEslintConfigForVue ,
9394 )
9495
9596 if ( lastExtendedConfigIndex === - 1 ) {
@@ -99,13 +100,12 @@ function insertAndReorderConfigs(
99100 const vueFiles = groupVueFiles ( projectOptions . rootDir ! )
100101 const configsWithoutTypeAwareRules = configs . map ( extractTypeAwareRules )
101102
102- const hasTypeAwarePresets = configs . some (
103+ const hasTypeAwareConfigs = configs . some (
103104 config =>
104- typeof config === 'string' &&
105- ! config . endsWith ( 'disableTypeChecked' ) &&
106- ( config . includes ( 'TypeChecked' ) || config . endsWith ( 'all' ) ) ,
105+ config instanceof TsEslintConfigForVue && config . needsTypeChecking ( ) ,
107106 )
108- const needsTypeAwareLinting = hasTypeAwarePresets || userTypeAwareConfigs . length > 0
107+ const needsTypeAwareLinting =
108+ hasTypeAwareConfigs || userTypeAwareConfigs . length > 0
109109
110110 return [
111111 ...configsWithoutTypeAwareRules . slice ( 0 , lastExtendedConfigIndex + 1 ) ,
@@ -130,9 +130,9 @@ function insertAndReorderConfigs(
130130}
131131
132132function extractTypeAwareRules (
133- config : ConfigOrVueTsPreset ,
134- ) : ConfigOrVueTsPreset {
135- if ( typeof config === 'string' ) {
133+ config : ConfigObjectOrPlaceholder ,
134+ ) : ConfigObjectOrPlaceholder {
135+ if ( config instanceof TsEslintConfigForVue ) {
136136 return config
137137 }
138138
@@ -148,7 +148,7 @@ function extractTypeAwareRules(
148148 if ( typeAwareRuleEntries . length > 0 ) {
149149 userTypeAwareConfigs . push ( {
150150 rules : Object . fromEntries ( typeAwareRuleEntries ) ,
151- ...( config . files && { files : config . files } ) ,
151+ ...( config . files && { files : config . files } ) ,
152152 } )
153153 }
154154
0 commit comments