@@ -84,10 +84,12 @@ export default class TslintBuilder implements Builder<TslintBuilderOptions> {
8484 let result : undefined | tslint . LintResult ;
8585 if ( options . tsConfig ) {
8686 const tsConfigs = Array . isArray ( options . tsConfig ) ? options . tsConfig : [ options . tsConfig ] ;
87+ const allPrograms =
88+ tsConfigs . map ( tsConfig => Linter . createProgram ( path . resolve ( systemRoot , tsConfig ) ) ) ;
8789
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 ) ;
9193 if ( result == undefined ) {
9294 result = partial ;
9395 } else {
@@ -152,6 +154,7 @@ function lint(
152154 tslintConfigPath : string | null ,
153155 options : TslintBuilderOptions ,
154156 program ?: ts . Program ,
157+ allPrograms ?: ts . Program [ ] ,
155158) {
156159 const Linter = projectTslint . Linter ;
157160 const Configuration = projectTslint . Configuration ;
@@ -167,7 +170,21 @@ function lint(
167170 let lastDirectory ;
168171 let configLoad ;
169172 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+ }
171188
172189 // Only check for a new tslint config if the path changes.
173190 const currentDirectory = path . dirname ( file ) ;
@@ -176,7 +193,7 @@ function lint(
176193 lastDirectory = currentDirectory ;
177194 }
178195
179- if ( contents && configLoad ) {
196+ if ( configLoad ) {
180197 linter . lint ( file , contents , configLoad . results ) ;
181198 }
182199 }
@@ -217,22 +234,7 @@ function getFilesToLint(
217234 return programFiles ;
218235}
219236
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 {
236238 // NOTE: The tslint CLI checks for and excludes MPEG transport streams; this does not.
237239 try {
238240 return stripBom ( readFileSync ( file , 'utf-8' ) ) ;
0 commit comments