@@ -15,7 +15,37 @@ export default function createConfig({
15
15
extends : configNamesToExtend = [ 'recommended' ] ,
16
16
supportedScriptLangs = { ts : true , tsx : false , js : false , jsx : false } ,
17
17
} : ConfigOptions = { } ) : ConfigArray {
18
- const mayHaveJsx = supportedScriptLangs . jsx || supportedScriptLangs . tsx
18
+ const mayHaveJsxInSfc = supportedScriptLangs . jsx || supportedScriptLangs . tsx
19
+ const needsTypeAwareLinting = configNamesToExtend . some ( name =>
20
+ name . endsWith ( '-type-checked' ) ,
21
+ )
22
+
23
+ // Type-aware linting is in conflict with JSX syntax in `.vue` files
24
+ // [!NOTE TO MYSELF] There's room for improvement here.
25
+ // We could disable type-aware linting *only* for `.vue` files with JSX syntax.
26
+ // Then the following error can be changed to a warning.
27
+ if ( needsTypeAwareLinting && mayHaveJsxInSfc ) {
28
+ throw new Error (
29
+ 'Type-aware linting is not supported in Vue SFCs with JSX syntax. ' +
30
+ 'Please disable type-aware linting or set `supportedScriptLangs.jsx` ' +
31
+ 'and `supportedScriptLangs.tsx` to `false`.' ,
32
+ )
33
+ }
34
+
35
+ const noProjectServiceForVue = mayHaveJsxInSfc
36
+ const projectServiceConfigs : ConfigArray = [ ]
37
+
38
+ if ( noProjectServiceForVue ) {
39
+ projectServiceConfigs . push ( {
40
+ name : 'vue-typescript/project-service-for-vue' ,
41
+ files : [ '*.vue' , '**/*.vue' ] ,
42
+ languageOptions : {
43
+ parserOptions : {
44
+ projectService : false ,
45
+ } ,
46
+ } ,
47
+ } )
48
+ }
19
49
20
50
return tseslint . config (
21
51
...configNamesToExtend
@@ -42,21 +72,19 @@ export default function createConfig({
42
72
parser : {
43
73
// Fallback to espree for js/jsx scripts, as well as SFCs without scripts
44
74
// for better performance.
45
- 'js' : 'espree' ,
46
- ' jsx' : 'espree' ,
75
+ js : 'espree' ,
76
+ jsx : 'espree' ,
47
77
48
- 'ts' : tseslintParser ,
49
- ' tsx' : tseslintParser ,
78
+ ts : tseslintParser ,
79
+ tsx : tseslintParser ,
50
80
51
81
// Leave the template parser unspecified,
52
82
// so that it could be determined by `<script lang="...">`
53
83
} ,
54
84
ecmaFeatures : {
55
- jsx : mayHaveJsx ,
85
+ jsx : mayHaveJsxInSfc ,
56
86
} ,
57
87
extraFileExtensions : [ 'vue' ] ,
58
- // type-aware linting is in conflict with jsx syntax in `.vue` files
59
- projectService : ! mayHaveJsx ,
60
88
} ,
61
89
} ,
62
90
rules : {
@@ -73,5 +101,7 @@ export default function createConfig({
73
101
] ,
74
102
} ,
75
103
} ,
104
+
105
+ ...projectServiceConfigs ,
76
106
)
77
107
}
0 commit comments