@@ -2,6 +2,7 @@ import * as chalk from 'chalk';
22import * as fs from 'fs' ;
33import * as glob from 'glob' ;
44import * as path from 'path' ;
5+ import { satisfies } from 'semver' ;
56import * as ts from 'typescript' ;
67import { requireProjectModule } from '../utilities/require-project-module' ;
78
@@ -57,16 +58,20 @@ export default Task.extend({
5758 fix : options . fix ,
5859 formatter : options . format
5960 } ;
60- const lintProgram = options . typeCheck ? program : undefined ;
61- const linter = new Linter ( lintOptions , lintProgram ) ;
61+
62+ // TSLint < 5.5 has a bug with fix and project used in combination.
63+ // previous behavior of typeCheck option is maintained for those versions
64+ if ( satisfies ( Linter . VERSION , '< 5.5' ) && ! options . typeCheck ) {
65+ program = undefined ;
66+ }
67+
68+ const linter = new Linter ( lintOptions , program ) ;
6269
6370 let lastDirectory : string ;
6471 let configLoad : any ;
6572 files . forEach ( ( file ) => {
66- const fileContents = getFileContents ( file , program ) ;
67- if ( ! fileContents ) {
68- return ;
69- }
73+ // The linter retrieves the SourceFile TS node directly if a program is used
74+ const fileContents = program ? undefined : getFileContents ( file ) ;
7075
7176 // Only check for a new tslint config if path changes
7277 const currentDirectory = path . dirname ( file ) ;
@@ -153,21 +158,14 @@ function getFilesToLint(program: ts.Program, lintConfig: CliLintConfig, Linter:
153158 return files ;
154159}
155160
156- function getFileContents ( file : string , program ?: ts . Program ) : string {
161+ function getFileContents ( file : string ) : string {
157162 let contents : string ;
158163
159- if ( program ) {
160- const sourceFile = program . getSourceFile ( file ) ;
161- if ( sourceFile ) {
162- contents = sourceFile . getFullText ( ) ;
163- }
164- } else {
165- // NOTE: The tslint CLI checks for and excludes MPEG transport streams; this does not.
166- try {
167- contents = fs . readFileSync ( file , 'utf8' ) ;
168- } catch ( e ) {
169- throw new SilentError ( `Could not read file "${ file } ".` ) ;
170- }
164+ // NOTE: The tslint CLI checks for and excludes MPEG transport streams; this does not.
165+ try {
166+ contents = fs . readFileSync ( file , 'utf8' ) ;
167+ } catch ( e ) {
168+ throw new SilentError ( `Could not read file "${ file } ".` ) ;
171169 }
172170
173171 return contents ;
0 commit comments