@@ -61,17 +61,19 @@ export class IncrementalChecker {
61
61
62
62
// it's shared between compilations
63
63
this . files = new FilesRegister ( ( ) => ( {
64
- // data shape
65
- source : undefined ,
66
- linted : false ,
67
- lints : [ ]
64
+ // data shape
65
+ source : undefined ,
66
+ linted : false ,
67
+ lints : [ ]
68
68
} ) ) ;
69
69
}
70
70
71
71
static loadProgramConfig ( configFile : string ) {
72
72
return ts . parseJsonConfigFileContent (
73
73
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
74
- Object . assign ( ts . readConfigFile ( configFile , ts . sys . readFile ) . config , { isolatedModules : false } ) ,
74
+ Object . assign ( ts . readConfigFile ( configFile , ts . sys . readFile ) . config , {
75
+ isolatedModules : false
76
+ } ) ,
75
77
ts . sys ,
76
78
path . dirname ( configFile )
77
79
) ;
@@ -80,7 +82,9 @@ export class IncrementalChecker {
80
82
static loadLinterConfig ( configFile : string ) : ConfigurationFile {
81
83
const tslint = require ( 'tslint' ) ;
82
84
83
- return tslint . Configuration . loadConfigurationFromPath ( configFile ) as ConfigurationFile ;
85
+ return tslint . Configuration . loadConfigurationFromPath (
86
+ configFile
87
+ ) as ConfigurationFile ;
84
88
}
85
89
86
90
static createProgram (
@@ -107,7 +111,7 @@ export class IncrementalChecker {
107
111
108
112
// get source file only if there is no source in files register
109
113
if ( ! files . has ( filePath ) || ! files . getData ( filePath ) . source ) {
110
- files . mutateData ( filePath , ( data ) => {
114
+ files . mutateData ( filePath , data => {
111
115
data . source = realGetSourceFile ( filePath , languageVersion , onError ) ;
112
116
} ) ;
113
117
}
@@ -129,13 +133,21 @@ export class IncrementalChecker {
129
133
return new tslint . Linter ( { fix : false } , program ) ;
130
134
}
131
135
132
- static isFileExcluded ( filePath : string , linterExclusions : minimatch . IMinimatch [ ] ) : boolean {
133
- return endsWith ( filePath , '.d.ts' ) || linterExclusions . some ( matcher => matcher . match ( filePath ) ) ;
136
+ static isFileExcluded (
137
+ filePath : string ,
138
+ linterExclusions : minimatch . IMinimatch [ ]
139
+ ) : boolean {
140
+ return (
141
+ endsWith ( filePath , '.d.ts' ) ||
142
+ linterExclusions . some ( matcher => matcher . match ( filePath ) )
143
+ ) ;
134
144
}
135
145
136
146
nextIteration ( ) {
137
147
if ( ! this . watcher ) {
138
- const watchExtensions = this . vue ? [ '.ts' , '.tsx' , '.vue' ] : [ '.ts' , '.tsx' ] ;
148
+ const watchExtensions = this . vue
149
+ ? [ '.ts' , '.tsx' , '.vue' ]
150
+ : [ '.ts' , '.tsx' ] ;
139
151
this . watcher = new FilesWatcher ( this . watchPaths , watchExtensions ) ;
140
152
141
153
// connect watcher with register
@@ -150,13 +162,20 @@ export class IncrementalChecker {
150
162
}
151
163
152
164
if ( ! this . linterConfig && this . linterConfigFile ) {
153
- this . linterConfig = IncrementalChecker . loadLinterConfig ( this . linterConfigFile ) ;
154
-
155
- if ( this . linterConfig . linterOptions && this . linterConfig . linterOptions . exclude ) {
165
+ this . linterConfig = IncrementalChecker . loadLinterConfig (
166
+ this . linterConfigFile
167
+ ) ;
168
+
169
+ if (
170
+ this . linterConfig . linterOptions &&
171
+ this . linterConfig . linterOptions . exclude
172
+ ) {
156
173
// Pre-build minimatch patterns to avoid additional overhead later on.
157
174
// Note: Resolving the path is required to properly match against the full file paths,
158
175
// and also deals with potential cross-platform problems regarding path separators.
159
- this . linterExclusions = this . linterConfig . linterOptions . exclude . map ( pattern => new minimatch . Minimatch ( path . resolve ( pattern ) ) ) ;
176
+ this . linterExclusions = this . linterConfig . linterOptions . exclude . map (
177
+ pattern => new minimatch . Minimatch ( path . resolve ( pattern ) )
178
+ ) ;
160
179
}
161
180
}
162
181
@@ -168,7 +187,9 @@ export class IncrementalChecker {
168
187
}
169
188
170
189
loadVueProgram ( ) {
171
- this . programConfig = this . programConfig || VueProgram . loadProgramConfig ( this . programConfigFile ) ;
190
+ this . programConfig =
191
+ this . programConfig ||
192
+ VueProgram . loadProgramConfig ( this . programConfigFile ) ;
172
193
173
194
return VueProgram . createProgram (
174
195
this . programConfig ,
@@ -180,9 +201,16 @@ export class IncrementalChecker {
180
201
}
181
202
182
203
loadDefaultProgram ( ) {
183
- this . programConfig = this . programConfig || IncrementalChecker . loadProgramConfig ( this . programConfigFile ) ;
204
+ this . programConfig =
205
+ this . programConfig ||
206
+ IncrementalChecker . loadProgramConfig ( this . programConfigFile ) ;
184
207
185
- return IncrementalChecker . createProgram ( this . programConfig , this . files , this . watcher , this . program ) ;
208
+ return IncrementalChecker . createProgram (
209
+ this . programConfig ,
210
+ this . files ,
211
+ this . watcher ,
212
+ this . program
213
+ ) ;
186
214
}
187
215
188
216
hasLinter ( ) {
@@ -195,18 +223,30 @@ export class IncrementalChecker {
195
223
const filesToCheck = this . program . getSourceFiles ( ) ;
196
224
197
225
// calculate subset of work to do
198
- const workSet = new WorkSet ( filesToCheck , this . workNumber , this . workDivision ) ;
226
+ const workSet = new WorkSet (
227
+ filesToCheck ,
228
+ this . workNumber ,
229
+ this . workDivision
230
+ ) ;
199
231
200
232
// check given work set
201
233
workSet . forEach ( sourceFile => {
202
234
if ( cancellationToken ) {
203
235
cancellationToken . throwIfCancellationRequested ( ) ;
204
236
}
205
237
206
- const diagnosticsToRegister : ReadonlyArray < ts . Diagnostic > = this . checkSyntacticErrors
238
+ const diagnosticsToRegister : ReadonlyArray < ts . Diagnostic > = this
239
+ . checkSyntacticErrors
207
240
? [ ]
208
- . concat ( this . program . getSemanticDiagnostics ( sourceFile , cancellationToken ) )
209
- . concat ( this . program . getSyntacticDiagnostics ( sourceFile , cancellationToken ) )
241
+ . concat (
242
+ this . program . getSemanticDiagnostics ( sourceFile , cancellationToken )
243
+ )
244
+ . concat (
245
+ this . program . getSyntacticDiagnostics (
246
+ sourceFile ,
247
+ cancellationToken
248
+ )
249
+ )
210
250
: this . program . getSemanticDiagnostics ( sourceFile , cancellationToken ) ;
211
251
212
252
diagnostics . push . apply ( diagnostics , diagnosticsToRegister ) ;
@@ -224,12 +264,20 @@ export class IncrementalChecker {
224
264
}
225
265
226
266
// select files to lint
227
- const filesToLint = this . files . keys ( ) . filter ( filePath =>
228
- ! this . files . getData ( filePath ) . linted && ! IncrementalChecker . isFileExcluded ( filePath , this . linterExclusions )
229
- ) ;
267
+ const filesToLint = this . files
268
+ . keys ( )
269
+ . filter (
270
+ filePath =>
271
+ ! this . files . getData ( filePath ) . linted &&
272
+ ! IncrementalChecker . isFileExcluded ( filePath , this . linterExclusions )
273
+ ) ;
230
274
231
275
// calculate subset of work to do
232
- const workSet = new WorkSet ( filesToLint , this . workNumber , this . workDivision ) ;
276
+ const workSet = new WorkSet (
277
+ filesToLint ,
278
+ this . workNumber ,
279
+ this . workDivision
280
+ ) ;
233
281
234
282
// lint given work set
235
283
workSet . forEach ( fileName => {
@@ -239,11 +287,11 @@ export class IncrementalChecker {
239
287
this . linter . lint ( fileName , undefined , this . linterConfig ) ;
240
288
} catch ( e ) {
241
289
if (
242
- fs . existsSync ( fileName ) &&
243
- // check the error type due to file system lag
244
- ! ( e instanceof Error ) &&
245
- ! ( e . constructor . name === 'FatalError' ) &&
246
- ! ( e . message && e . message . trim ( ) . startsWith ( " Invalid source file" ) )
290
+ fs . existsSync ( fileName ) &&
291
+ // check the error type due to file system lag
292
+ ! ( e instanceof Error ) &&
293
+ ! ( e . constructor . name === 'FatalError' ) &&
294
+ ! ( e . message && e . message . trim ( ) . startsWith ( ' Invalid source file' ) )
247
295
) {
248
296
// it's not because file doesn't exist - throw error
249
297
throw e ;
@@ -269,9 +317,13 @@ export class IncrementalChecker {
269
317
} ) ;
270
318
271
319
// get all lints
272
- const lints = this . files . keys ( ) . reduce ( ( innerLints , filePath ) =>
273
- innerLints . concat ( this . files . getData ( filePath ) . lints ) ,
274
- [ ] ) ;
320
+ const lints = this . files
321
+ . keys ( )
322
+ . reduce (
323
+ ( innerLints , filePath ) =>
324
+ innerLints . concat ( this . files . getData ( filePath ) . lints ) ,
325
+ [ ]
326
+ ) ;
275
327
276
328
// normalize and deduplicate lints
277
329
return NormalizedMessage . deduplicate (
0 commit comments