1
- import { CLIEngine , Linter } from 'eslint' ;
1
+ import { ESLint , Linter } from 'eslint' ;
2
2
import { configs } from 'eslint-plugin-vue' ;
3
3
import { Diagnostic , Range , DiagnosticSeverity } from 'vscode-languageserver-types' ;
4
4
import type { TextDocument } from 'vscode-languageserver-textdocument' ;
@@ -18,32 +18,27 @@ function toDiagnostic(error: Linter.LintMessage): Diagnostic {
18
18
} ;
19
19
}
20
20
21
- export function doESLintValidation ( document : TextDocument , engine : CLIEngine ) : Diagnostic [ ] {
21
+ export async function doESLintValidation ( document : TextDocument , engine : ESLint ) : Promise < Diagnostic [ ] > {
22
22
const rawText = document . getText ( ) ;
23
23
// skip checking on empty template
24
24
if ( rawText . replace ( / \s / g, '' ) === '' ) {
25
25
return [ ] ;
26
26
}
27
27
const text = rawText . replace ( / { 10 } / , '<template>' ) + '</template>' ;
28
- const report = engine . executeOnText ( text , document . uri ) ;
28
+ const report = await engine . lintText ( text , { filePath : document . uri } ) ;
29
29
30
- return report . results [ 0 ] ? report . results [ 0 ] . messages . map ( toDiagnostic ) : [ ] ;
30
+ return report ?. [ 0 ] . messages . map ( toDiagnostic ) ?? [ ] ;
31
31
}
32
32
33
33
export function createLintEngine ( vueVersion : VueVersion ) {
34
34
const SERVER_ROOT = resolve ( __dirname , '../../../../' ) ;
35
35
36
- const basicConfig = {
37
- useEslintrc : false ,
38
- // So ESLint can find the bundled eslint-plugin-vue
39
- cwd : SERVER_ROOT ,
40
- ...configs . base
41
- } ;
42
-
43
36
const versionSpecificConfig = vueVersion === VueVersion . V30 ? configs [ 'vue3-essential' ] : configs . essential ;
44
37
45
- return new CLIEngine ( {
46
- ...basicConfig ,
47
- ...versionSpecificConfig
38
+ return new ESLint ( {
39
+ useEslintrc : false ,
40
+ cwd : SERVER_ROOT ,
41
+ baseConfig : configs . base ,
42
+ overrideConfig : versionSpecificConfig
48
43
} ) ;
49
44
}
0 commit comments