@@ -84,10 +84,12 @@ export default class TslintBuilder implements Builder<TslintBuilderOptions> {
84
84
let result : undefined | tslint . LintResult ;
85
85
if ( options . tsConfig ) {
86
86
const tsConfigs = Array . isArray ( options . tsConfig ) ? options . tsConfig : [ options . tsConfig ] ;
87
+ const allPrograms =
88
+ tsConfigs . map ( tsConfig => Linter . createProgram ( path . resolve ( systemRoot , tsConfig ) ) ) ;
87
89
88
- for ( const tsConfig of tsConfigs ) {
89
- const program = Linter . createProgram ( path . resolve ( systemRoot , tsConfig ) ) ;
90
- const partial = lint ( projectTslint , systemRoot , tslintConfigPath , options , program ) ;
90
+ for ( const program of allPrograms ) {
91
+ const partial
92
+ = lint ( projectTslint , systemRoot , tslintConfigPath , options , program , allPrograms ) ;
91
93
if ( result == undefined ) {
92
94
result = partial ;
93
95
} else {
@@ -152,6 +154,7 @@ function lint(
152
154
tslintConfigPath : string | null ,
153
155
options : TslintBuilderOptions ,
154
156
program ?: ts . Program ,
157
+ allPrograms ?: ts . Program [ ] ,
155
158
) {
156
159
const Linter = projectTslint . Linter ;
157
160
const Configuration = projectTslint . Configuration ;
@@ -167,7 +170,21 @@ function lint(
167
170
let lastDirectory ;
168
171
let configLoad ;
169
172
for ( const file of files ) {
170
- const contents = getFileContents ( file , options , program ) ;
173
+ let contents = '' ;
174
+ if ( program && allPrograms ) {
175
+ if ( ! program . getSourceFile ( file ) ) {
176
+ if ( ! allPrograms . some ( p => p . getSourceFile ( file ) !== undefined ) ) {
177
+ // File is not part of any typescript program
178
+ throw new Error (
179
+ `File '${ file } ' is not part of a TypeScript project '${ options . tsConfig } '.` ) ;
180
+ }
181
+
182
+ // if the Source file exists but it's not in the current program skip
183
+ continue ;
184
+ }
185
+ } else {
186
+ contents = getFileContents ( file ) ;
187
+ }
171
188
172
189
// Only check for a new tslint config if the path changes.
173
190
const currentDirectory = path . dirname ( file ) ;
@@ -176,7 +193,7 @@ function lint(
176
193
lastDirectory = currentDirectory ;
177
194
}
178
195
179
- if ( contents && configLoad ) {
196
+ if ( configLoad ) {
180
197
linter . lint ( file , contents , configLoad . results ) ;
181
198
}
182
199
}
@@ -217,22 +234,7 @@ function getFilesToLint(
217
234
return programFiles ;
218
235
}
219
236
220
- function getFileContents (
221
- file : string ,
222
- options : TslintBuilderOptions ,
223
- program ?: ts . Program ,
224
- ) : string | undefined {
225
- // The linter retrieves the SourceFile TS node directly if a program is used
226
- if ( program ) {
227
- if ( program . getSourceFile ( file ) == undefined ) {
228
- const message = `File '${ file } ' is not part of the TypeScript project '${ options . tsConfig } '.` ;
229
- throw new Error ( message ) ;
230
- }
231
-
232
- // TODO: this return had to be commented out otherwise no file would be linted, figure out why.
233
- // return undefined;
234
- }
235
-
237
+ function getFileContents ( file : string ) : string {
236
238
// NOTE: The tslint CLI checks for and excludes MPEG transport streams; this does not.
237
239
try {
238
240
return stripBom ( readFileSync ( file , 'utf-8' ) ) ;
0 commit comments