33import chalk from 'chalk' ;
44import * as fs from 'fs' ;
55import * as glob from 'glob' ;
6+ import { Minimatch } from 'minimatch' ;
67import * as path from 'path' ;
78import { satisfies } from 'semver' ;
89import * as ts from 'typescript' ;
@@ -17,6 +18,7 @@ const Task = require('../ember-cli/lib/models/task');
1718export interface CliLintConfig {
1819 files ?: ( string | string [ ] ) ;
1920 project ?: string ;
21+ projectOnly ?: boolean ;
2022 tslintConfig ?: string ;
2123 exclude ?: ( string | string [ ] ) ;
2224}
@@ -137,34 +139,38 @@ export default Task.extend({
137139 }
138140} ) ;
139141
142+ function normalizeArrayOption < T > ( option : T | Array < T > ) : Array < T > {
143+ return Array . isArray ( option ) ? option : [ option ] ;
144+ }
145+
140146function getFilesToLint (
141147 program : ts . Program ,
142148 lintConfig : CliLintConfig ,
143149 linter : typeof tslint . Linter ,
144150) : string [ ] {
145- let files : string [ ] = [ ] ;
151+ const providedFiles = lintConfig . files && normalizeArrayOption ( lintConfig . files ) ;
152+ const ignore = lintConfig . exclude && normalizeArrayOption ( lintConfig . exclude ) ;
146153
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 ) , [ ] ) ;
151158 }
152159
153- let globOptions = { } ;
160+ if ( ! program ) {
161+ return [ ] ;
162+ }
154163
155- if ( lintConfig . exclude ) {
156- const excludePatterns = Array . isArray ( lintConfig . exclude )
157- ? lintConfig . exclude
158- : [ lintConfig . exclude ] ;
164+ let programFiles = linter . getFileNames ( program ) ;
159165
160- globOptions = { ignore : excludePatterns , nodir : true } ;
161- }
166+ if ( ignore && ignore . length > 0 ) {
167+ const ignoreMatchers = ignore . map ( pattern => new Minimatch ( pattern ) ) ;
162168
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+ }
166172
167- return files ;
173+ return programFiles ;
168174}
169175
170176function getFileContents ( file : string ) : string {
0 commit comments