@@ -2,6 +2,7 @@ import * as chalk from 'chalk';
2
2
import * as fs from 'fs' ;
3
3
import * as glob from 'glob' ;
4
4
import * as path from 'path' ;
5
+ import { satisfies } from 'semver' ;
5
6
import * as ts from 'typescript' ;
6
7
import { requireProjectModule } from '../utilities/require-project-module' ;
7
8
@@ -57,16 +58,20 @@ export default Task.extend({
57
58
fix : options . fix ,
58
59
formatter : options . format
59
60
} ;
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 ) ;
62
69
63
70
let lastDirectory : string ;
64
71
let configLoad : any ;
65
72
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 ) ;
70
75
71
76
// Only check for a new tslint config if path changes
72
77
const currentDirectory = path . dirname ( file ) ;
@@ -153,21 +158,14 @@ function getFilesToLint(program: ts.Program, lintConfig: CliLintConfig, Linter:
153
158
return files ;
154
159
}
155
160
156
- function getFileContents ( file : string , program ?: ts . Program ) : string {
161
+ function getFileContents ( file : string ) : string {
157
162
let contents : string ;
158
163
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 } ".` ) ;
171
169
}
172
170
173
171
return contents ;
0 commit comments