1
+ import process from 'node:process'
1
2
import * as tseslint from 'typescript-eslint'
2
-
3
- import type { VueTsPreset } from './configs'
4
- import { getConfigForPlaceholder } from './configs'
3
+ import { TsEslintConfigForVue } from './configs'
5
4
import groupVueFiles from './groupVueFiles'
6
5
import {
7
6
additionalRulesRequiringParserServices ,
@@ -10,17 +9,16 @@ import {
10
9
createTypeCheckingConfigs ,
11
10
} from './internals'
12
11
12
+ import type { ScriptLang } from './internals'
13
+
13
14
type ConfigArray = ReturnType < typeof tseslint . config >
14
15
type Rules = NonNullable < ConfigArray [ number ] [ 'rules' ] >
15
16
16
- type ConfigOrVueTsPreset = ConfigArray [ number ] | VueTsPreset
17
+ type ConfigObjectOrPlaceholder = ConfigArray [ number ] | TsEslintConfigForVue
17
18
type InfiniteDepthConfigWithVueSupport =
18
- | ConfigOrVueTsPreset
19
+ | ConfigObjectOrPlaceholder
19
20
| InfiniteDepthConfigWithVueSupport [ ]
20
21
21
- import process from 'node:process'
22
- import type { ScriptLang } from './internals'
23
-
24
22
export type ProjectOptions = {
25
23
scriptLangs ?: ScriptLang [ ]
26
24
rootDir ?: string
@@ -48,11 +46,14 @@ export function configureVueProject(userOptions: ProjectOptions) {
48
46
export function defineConfigWithVueTs (
49
47
...configs : InfiniteDepthConfigWithVueSupport [ ]
50
48
) : 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 ,
56
57
)
57
58
58
59
return tseslint . config ( ...normalizedConfigs )
@@ -86,10 +87,10 @@ type ExtractedConfig = {
86
87
const userTypeAwareConfigs : ExtractedConfig [ ] = [ ]
87
88
88
89
function insertAndReorderConfigs (
89
- configs : Array < ConfigOrVueTsPreset > ,
90
- ) : Array < ConfigOrVueTsPreset > {
90
+ configs : Array < ConfigObjectOrPlaceholder > ,
91
+ ) : Array < ConfigObjectOrPlaceholder > {
91
92
const lastExtendedConfigIndex = configs . findLastIndex (
92
- config => typeof config === 'string' ,
93
+ config => config instanceof TsEslintConfigForVue ,
93
94
)
94
95
95
96
if ( lastExtendedConfigIndex === - 1 ) {
@@ -99,13 +100,12 @@ function insertAndReorderConfigs(
99
100
const vueFiles = groupVueFiles ( projectOptions . rootDir ! )
100
101
const configsWithoutTypeAwareRules = configs . map ( extractTypeAwareRules )
101
102
102
- const hasTypeAwarePresets = configs . some (
103
+ const hasTypeAwareConfigs = configs . some (
103
104
config =>
104
- typeof config === 'string' &&
105
- ! config . endsWith ( 'disableTypeChecked' ) &&
106
- ( config . includes ( 'TypeChecked' ) || config . endsWith ( 'all' ) ) ,
105
+ config instanceof TsEslintConfigForVue && config . needsTypeChecking ( ) ,
107
106
)
108
- const needsTypeAwareLinting = hasTypeAwarePresets || userTypeAwareConfigs . length > 0
107
+ const needsTypeAwareLinting =
108
+ hasTypeAwareConfigs || userTypeAwareConfigs . length > 0
109
109
110
110
return [
111
111
...configsWithoutTypeAwareRules . slice ( 0 , lastExtendedConfigIndex + 1 ) ,
@@ -130,9 +130,9 @@ function insertAndReorderConfigs(
130
130
}
131
131
132
132
function extractTypeAwareRules (
133
- config : ConfigOrVueTsPreset ,
134
- ) : ConfigOrVueTsPreset {
135
- if ( typeof config === 'string' ) {
133
+ config : ConfigObjectOrPlaceholder ,
134
+ ) : ConfigObjectOrPlaceholder {
135
+ if ( config instanceof TsEslintConfigForVue ) {
136
136
return config
137
137
}
138
138
@@ -148,7 +148,7 @@ function extractTypeAwareRules(
148
148
if ( typeAwareRuleEntries . length > 0 ) {
149
149
userTypeAwareConfigs . push ( {
150
150
rules : Object . fromEntries ( typeAwareRuleEntries ) ,
151
- ...( config . files && { files : config . files } ) ,
151
+ ...( config . files && { files : config . files } ) ,
152
152
} )
153
153
}
154
154
0 commit comments