@@ -195,33 +195,41 @@ extension Configuration {
195195
196196 func inputPaths( ) throws -> [ Path ] {
197197 var inputPaths = Set < Path > ( )
198-
199- let inputDirectories = Set ( inputPathStrings
200- . lazy
201- . map { self . projectPath + $0 }
202- . filter { $0. exists && $0. isDirectory }
203- . map { $0. absolute ( ) . string } )
204-
205- if inputDirectories. isEmpty == false {
206- let grepArguments = [ " -lR " , " -e " , Configuration . annotationRegex, " -e " , Configuration . propertyWrapperRegex] + Array( inputDirectories)
207- inputPaths. formUnion ( try shellOut ( to: " grep " , arguments: grepArguments)
208- . split ( separator: " \n " )
209- . lazy
210- . map { Path ( String ( $0) ) }
211- . filter { $0. extension == " swift " } )
212- }
213198
214199 inputPaths. formUnion ( inputPathStrings
215200 . lazy
216201 . map { self . projectPath + $0 }
202+ . flatMap { $0. isFile ? [ $0] : self . recursivePathsByPattern ( fromDirectory: $0) }
217203 . filter { $0. exists && $0. isFile && $0. extension == " swift " } )
218204
219205 inputPaths. subtract ( try ignoredPathStrings
220206 . lazy
221207 . map { self . projectPath + $0 }
222- . flatMap { $0. isFile ? [ $0] : recursive ? try $0 . recursiveChildren ( ) : try $0 . children ( ) }
208+ . flatMap { $0. isFile ? [ $0] : try paths ( fromDirectory : $0 ) }
223209 . filter { $0. extension == " swift " } )
224210
225211 return inputPaths. sorted ( )
226212 }
213+
214+ private func recursivePathsByPattern( fromDirectory directory: Path ) -> [ Path ] {
215+ let grepArguments = [
216+ " -lR " ,
217+ " -e " , Configuration . annotationRegex,
218+ " -e " , Configuration . propertyWrapperRegex,
219+ directory. absolute ( ) . string
220+ ]
221+ // if there are no files matching the pattern
222+ // command grep return exit 1, and ShellOut throws an exception with empty message
223+ guard let grepResult = try ? shellOut ( to: " grep " , arguments: grepArguments) else {
224+ return [ ]
225+ }
226+
227+ return grepResult
228+ . split ( separator: " \n " )
229+ . map { Path ( String ( $0) ) }
230+ }
231+
232+ private func paths( fromDirectory directory: Path ) throws -> [ Path ] {
233+ recursive ? try directory. recursiveChildren ( ) : try directory. children ( )
234+ }
227235}
0 commit comments