1
1
var ts = require ( 'typescript' ) ;
2
2
var fs = require ( 'fs' ) ;
3
3
var path = require ( 'path' ) ;
4
+ var endsWith = require ( 'lodash.endswith' ) ;
4
5
var FilesRegister = require ( './FilesRegister' ) ;
5
6
var FilesWatcher = require ( './FilesWatcher' ) ;
6
7
7
- function IncrementalChecker ( programConfigFile , linterConfigFile , watchPaths ) {
8
+ function IncrementalChecker ( programConfigFile , linterConfigFile , watchPaths ) {
8
9
this . programConfigFile = programConfigFile ;
9
10
this . linterConfigFile = linterConfigFile ;
10
11
this . watchPaths = watchPaths ;
@@ -25,11 +26,11 @@ IncrementalChecker.loadLinterConfig = function (configFile) {
25
26
return tslint . Configuration . loadConfigurationFromPath ( configFile ) ;
26
27
} ;
27
28
28
- IncrementalChecker . createProgram = function ( programConfig , register , watcher , oldProgram ) {
29
+ IncrementalChecker . createProgram = function ( programConfig , register , watcher , oldProgram ) {
29
30
var host = ts . createCompilerHost ( programConfig . options ) ;
30
31
var originGetSourceFile = host . getSourceFile ;
31
32
32
- host . getSourceFile = function ( filePath , languageVersion , onError ) {
33
+ host . getSourceFile = function ( filePath , languageVersion , onError ) {
33
34
// first check if watcher is watching file - if not - check it's mtime
34
35
if ( ! watcher . isWatchingFile ( filePath ) ) {
35
36
var stats = fs . statSync ( filePath ) ;
@@ -56,13 +57,13 @@ IncrementalChecker.createProgram = function(programConfig, register, watcher, ol
56
57
) ;
57
58
} ;
58
59
59
- IncrementalChecker . createLinter = function ( program ) {
60
+ IncrementalChecker . createLinter = function ( program ) {
60
61
var tslint = require ( 'tslint' ) ;
61
62
62
63
return new tslint . Linter ( { fix : false } , program ) ;
63
64
} ;
64
65
65
- IncrementalChecker . prototype . nextIteration = function ( ) {
66
+ IncrementalChecker . prototype . nextIteration = function ( ) {
66
67
this . register = new FilesRegister ( this . register ) ;
67
68
68
69
if ( ! this . watcher ) {
@@ -87,7 +88,7 @@ IncrementalChecker.prototype.nextIteration = function() {
87
88
this . linter = IncrementalChecker . createLinter ( this . program ) ;
88
89
} ;
89
90
90
- IncrementalChecker . prototype . getDiagnostics = function ( cancellationToken ) {
91
+ IncrementalChecker . prototype . getDiagnostics = function ( cancellationToken ) {
91
92
var diagnostics = this . program . getSemanticDiagnostics ( undefined , cancellationToken ) ;
92
93
93
94
return diagnostics . map ( function ( diagnostic ) {
@@ -106,11 +107,11 @@ IncrementalChecker.prototype.getDiagnostics = function(cancellationToken) {
106
107
} ) ;
107
108
} ;
108
109
109
- IncrementalChecker . prototype . getLints = function ( cancellationToken ) {
110
+ IncrementalChecker . prototype . getLints = function ( cancellationToken ) {
110
111
this . register . forEach ( function ( fileName , fileEntry ) {
111
112
cancellationToken . throwIfCancellationRequested ( ) ;
112
113
113
- if ( ! fileName . endsWith ( '.d.ts' ) && ! fileEntry . linted ) {
114
+ if ( ! endsWith ( fileName , '.d.ts' ) && ! fileEntry . linted ) {
114
115
this . linter . lint ( fileName , undefined , this . linterConfig ) ;
115
116
fileEntry . linted = true ;
116
117
}
@@ -134,6 +135,6 @@ IncrementalChecker.prototype.getLints = function(cancellationToken) {
134
135
file : lint . getFileName ( ) ,
135
136
line : position . line ,
136
137
character : position . character
137
- }
138
+ } ;
138
139
} ) ;
139
140
} ;
0 commit comments