3
3
import chalk from 'chalk' ;
4
4
import * as fs from 'fs' ;
5
5
import * as glob from 'glob' ;
6
+ import { Minimatch } from 'minimatch' ;
6
7
import * as path from 'path' ;
7
8
import { satisfies } from 'semver' ;
8
9
import * as ts from 'typescript' ;
@@ -17,6 +18,7 @@ const Task = require('../ember-cli/lib/models/task');
17
18
export interface CliLintConfig {
18
19
files ?: ( string | string [ ] ) ;
19
20
project ?: string ;
21
+ projectOnly ?: boolean ;
20
22
tslintConfig ?: string ;
21
23
exclude ?: ( string | string [ ] ) ;
22
24
}
@@ -137,34 +139,38 @@ export default Task.extend({
137
139
}
138
140
} ) ;
139
141
142
+ function normalizeArrayOption < T > ( option : T | Array < T > ) : Array < T > {
143
+ return Array . isArray ( option ) ? option : [ option ] ;
144
+ }
145
+
140
146
function getFilesToLint (
141
147
program : ts . Program ,
142
148
lintConfig : CliLintConfig ,
143
149
linter : typeof tslint . Linter ,
144
150
) : string [ ] {
145
- let files : string [ ] = [ ] ;
151
+ const providedFiles = lintConfig . files && normalizeArrayOption ( lintConfig . files ) ;
152
+ const ignore = lintConfig . exclude && normalizeArrayOption ( lintConfig . exclude ) ;
146
153
147
- if ( lintConfig . files ) {
148
- files = Array . isArray ( lintConfig . files ) ? lintConfig . files : [ lintConfig . files ] ;
149
- } else if ( program ) {
150
- files = linter . getFileNames ( program ) ;
154
+ if ( providedFiles ) {
155
+ return providedFiles
156
+ . map ( file => glob . sync ( file , { ignore , nodir : true } ) )
157
+ . reduce ( ( prev , curr ) => prev . concat ( curr ) , [ ] ) ;
151
158
}
152
159
153
- let globOptions = { } ;
160
+ if ( ! program ) {
161
+ return [ ] ;
162
+ }
154
163
155
- if ( lintConfig . exclude ) {
156
- const excludePatterns = Array . isArray ( lintConfig . exclude )
157
- ? lintConfig . exclude
158
- : [ lintConfig . exclude ] ;
164
+ let programFiles = linter . getFileNames ( program ) ;
159
165
160
- globOptions = { ignore : excludePatterns , nodir : true } ;
161
- }
166
+ if ( ignore && ignore . length > 0 ) {
167
+ const ignoreMatchers = ignore . map ( pattern => new Minimatch ( pattern ) ) ;
162
168
163
- files = files
164
- . map ( ( file : string ) => glob . sync ( file , globOptions ) )
165
- . reduce ( ( a : string [ ] , b : string [ ] ) => a . concat ( b ) , [ ] ) ;
169
+ programFiles = programFiles
170
+ . filter ( file => ! ignoreMatchers . some ( matcher => matcher . match ( file ) ) ) ;
171
+ }
166
172
167
- return files ;
173
+ return programFiles ;
168
174
}
169
175
170
176
function getFileContents ( file : string ) : string {
0 commit comments