@@ -6,6 +6,8 @@ import * as glob from 'glob';
6
6
import * as path from 'path' ;
7
7
import { satisfies } from 'semver' ;
8
8
import * as ts from 'typescript' ;
9
+ // @ignoreDep tslint - used only for type information
10
+ import * as tslint from 'tslint' ;
9
11
import { requireProjectModule } from '../utilities/require-project-module' ;
10
12
11
13
const SilentError = require ( 'silent-error' ) ;
@@ -41,9 +43,9 @@ export default Task.extend({
41
43
return Promise . resolve ( 0 ) ;
42
44
}
43
45
44
- const tslint = requireProjectModule ( projectRoot , 'tslint' ) ;
45
- const Linter = tslint . Linter ;
46
- const Configuration = tslint . Configuration ;
46
+ const projectTslint = requireProjectModule ( projectRoot , 'tslint' ) as typeof tslint ;
47
+ const Linter = projectTslint . Linter ;
48
+ const Configuration = projectTslint . Configuration ;
47
49
48
50
const result = lintConfigs
49
51
. map ( ( config ) => {
@@ -69,9 +71,9 @@ export default Task.extend({
69
71
70
72
const linter = new Linter ( lintOptions , program ) ;
71
73
72
- let lastDirectory : string ;
73
- let configLoad : any ;
74
- files . forEach ( ( file ) => {
74
+ let lastDirectory ;
75
+ let configLoad ;
76
+ for ( const file of files ) {
75
77
// The linter retrieves the SourceFile TS node directly if a program is used
76
78
const fileContents = program ? undefined : getFileContents ( file ) ;
77
79
@@ -83,13 +85,13 @@ export default Task.extend({
83
85
}
84
86
85
87
linter . lint ( file , fileContents , configLoad . results ) ;
86
- } ) ;
88
+ }
87
89
88
90
return linter . getResult ( ) ;
89
91
} )
90
92
. reduce ( ( total , current ) => {
91
93
const failures = current . failures
92
- . filter ( ( cf : any ) => ! total . failures . some ( ( ef : any ) => ef . equals ( cf ) ) ) ;
94
+ . filter ( cf => ! total . failures . some ( ef => ef . equals ( cf ) ) ) ;
93
95
total . failures = total . failures . concat ( ...failures ) ;
94
96
95
97
if ( current . fixes ) {
@@ -102,7 +104,7 @@ export default Task.extend({
102
104
} ) ;
103
105
104
106
if ( ! options . silent ) {
105
- const Formatter = tslint . findFormatter ( options . format ) ;
107
+ const Formatter = projectTslint . findFormatter ( options . format ) ;
106
108
if ( ! Formatter ) {
107
109
throw new SilentError ( chalk . red ( `Invalid lint format "${ options . format } ".` ) ) ;
108
110
}
@@ -134,13 +136,17 @@ export default Task.extend({
134
136
}
135
137
} ) ;
136
138
137
- function getFilesToLint ( program : ts . Program , lintConfig : CliLintConfig , Linter : any ) : string [ ] {
139
+ function getFilesToLint (
140
+ program : ts . Program ,
141
+ lintConfig : CliLintConfig ,
142
+ linter : typeof tslint . Linter ,
143
+ ) : string [ ] {
138
144
let files : string [ ] = [ ] ;
139
145
140
146
if ( lintConfig . files ) {
141
147
files = Array . isArray ( lintConfig . files ) ? lintConfig . files : [ lintConfig . files ] ;
142
148
} else if ( program ) {
143
- files = Linter . getFileNames ( program ) ;
149
+ files = linter . getFileNames ( program ) ;
144
150
}
145
151
146
152
let globOptions = { } ;
0 commit comments