1
1
import assert = require( "assert" ) ;
2
2
import { TypeScriptVersion } from "definitelytyped-header-parser" ;
3
+ import * as fs from "fs" ;
3
4
import { pathExists } from "fs-extra" ;
4
- import { join as joinPaths , normalize } from "path" ;
5
+ import { dirname , join as joinPaths , normalize } from "path" ;
5
6
import { Configuration , ILinterOptions , Linter } from "tslint" ;
6
7
import * as TsType from "typescript" ;
7
8
type Configuration = typeof Configuration ;
@@ -27,6 +28,28 @@ export async function lint(
27
28
if ( errors ) { return errors ; }
28
29
}
29
30
31
+ {
32
+ const { config } = TsType . readConfigFile ( tsconfigPath , TsType . sys . readFile ) ;
33
+ const parseConfigHost : TsType . ParseConfigHost = {
34
+ fileExists : fs . existsSync ,
35
+ readDirectory : TsType . sys . readDirectory ,
36
+ readFile : file => fs . readFileSync ( file , "utf8" ) ,
37
+ useCaseSensitiveFileNames : true ,
38
+ } ;
39
+ const projectDirectory = dirname ( tsconfigPath ) ;
40
+ const parsed = TsType . parseJsonConfigFileContent ( config , parseConfigHost , projectDirectory , { noEmit : true } ) ;
41
+ const program = TsType . createProgram ( parsed . fileNames . filter ( fileName => fileName . endsWith ( ".d.ts" ) ) , parsed . options ) ;
42
+ const diagnostics = TsType . getPreEmitDiagnostics ( program ) ;
43
+ if ( diagnostics . length ) {
44
+ const showDiags = TsType . formatDiagnostics ( diagnostics , {
45
+ getCanonicalFileName : f => f ,
46
+ getCurrentDirectory : ( ) => dirPath ,
47
+ getNewLine : ( ) => "\n" ,
48
+ } ) ;
49
+ return showDiags ;
50
+ }
51
+ }
52
+
30
53
const lintOptions : ILinterOptions = {
31
54
fix : false ,
32
55
formatter : "stylish" ,
0 commit comments