@@ -23,22 +23,29 @@ function toArray<T>(value: T | T[]): T[] {
23
23
}
24
24
25
25
export class TsEslintConfigForVue {
26
- constructor ( readonly configName : ExtendableConfigName ) {
27
- this . configName = configName
26
+ // the name property is here to provide better error messages when ESLint throws an error
27
+ name : string
28
+
29
+ #configName: ExtendableConfigName
30
+
31
+ constructor ( configName : ExtendableConfigName ) {
32
+ this . #configName = configName
33
+
34
+ this . name = `vueTsConfigs.${ configName } `
28
35
}
29
36
30
37
needsTypeChecking ( ) : boolean {
31
- if ( this . configName === 'disableTypeChecked' ) {
38
+ if ( this . # configName === 'disableTypeChecked' ) {
32
39
return false
33
40
}
34
- if ( this . configName === 'all' ) {
41
+ if ( this . # configName === 'all' ) {
35
42
return true
36
43
}
37
- return this . configName . includes ( 'TypeChecked' )
44
+ return this . # configName. includes ( 'TypeChecked' )
38
45
}
39
46
40
47
toConfigArray ( ) : FlatConfig . ConfigArray {
41
- return toArray ( tseslint . configs [ this . configName ] )
48
+ return toArray ( tseslint . configs [ this . # configName] )
42
49
. flat ( )
43
50
. map ( config =>
44
51
config . files && config . files . includes ( '**/*.ts' )
@@ -52,5 +59,17 @@ export class TsEslintConfigForVue {
52
59
}
53
60
54
61
export const vueTsConfigs = Object . fromEntries (
55
- CONFIG_NAMES . map ( name => [ name , new TsEslintConfigForVue ( name ) ] ) ,
62
+ CONFIG_NAMES . map ( name => [
63
+ name ,
64
+ new Proxy ( new TsEslintConfigForVue ( name ) , {
65
+ // `ownKeys` is called by ESLint when validating the config object.
66
+ // The only possible scenario where this is called is when the placeholder object
67
+ // isn't replaced, which means it's passed to ESLint without being wrapped by
68
+ // `defineConfigWithVueTs()`
69
+ // We throw an error here to provide a better error message to the user.
70
+ ownKeys ( ) {
71
+ throw new Error ( 'Please wrap the config object with `defineConfigWithVueTs()`' )
72
+ } ,
73
+ } ) ,
74
+ ] ) ,
56
75
) as Record < ExtendableConfigName , TsEslintConfigForVue >
0 commit comments