@@ -65,39 +65,67 @@ var findFixmes = function(file){
6565 } )
6666}
6767
68- var eligibleFile = function ( fp , excludePaths ) {
69- return ( excludePaths . indexOf ( fp . split ( "/code/" ) [ 1 ] ) < 0 ) &&
70- ! fs . lstatSync ( fp ) . isDirectory ( ) &&
71- ( excludeExtensions . indexOf ( path . extname ( fp ) ) < 0 )
68+ // Returns an array of unique array values not included in the other provided array
69+ var diff = function ( a1 , a2 ) {
70+ var result = [ ] ;
71+
72+ for ( var i = 0 ; i < a1 . length ; i ++ ) {
73+ if ( a2 . indexOf ( a1 [ i ] ) === - 1 ) {
74+ result . push ( a1 [ i ] ) ;
75+ }
76+
77+ }
78+ return result ;
7279}
7380
74- // Uses glob to traverse code directory and find files to analyze,
75- // excluding files passed in with by CLI config
76- var fileWalk = function ( excludePaths ) {
77- var analysisFiles = [ ] ;
78- var allFiles = glob . sync ( "/code/**/**" , { } ) ;
81+ // Returns all the file paths in the main directory that match the given pattern
82+ var buildFiles = function ( paths ) {
83+ var files = [ ] ;
7984
80- allFiles . forEach ( function ( file , i , a ) {
81- if ( eligibleFile ( file , excludePaths ) ) {
82- analysisFiles . push ( file ) ;
83- }
85+ paths . forEach ( function ( path , i , a ) {
86+ var pattern = "/code/" + path + "**"
87+ files . push . apply ( files , glob . sync ( pattern , { } ) ) ;
88+ } ) ;
89+
90+ return files ;
91+ }
92+
93+ // Filters the directory paths out
94+ var filterFiles = function ( files ) {
95+ return files . filter ( function ( file ) {
96+ return ! fs . lstatSync ( file ) . isDirectory ( ) ;
8497 } ) ;
8598
8699 return analysisFiles ;
87100}
88101
102+ // Returns file paths based on the exclude_paths values in config file
103+ var buildFilesWithExclusions = function ( exclusions ) {
104+ var allFiles = glob . sync ( "/code/**/**" , { } ) ;
105+ var excludedFiles = buildFiles ( exclusions ) ;
106+
107+ return diff ( allFiles , excludedFiles ) ;
108+ }
109+
110+ // Returns file paths based on the include_paths values in config file
111+ var buildFilesWithInclusions = function ( inclusions ) {
112+ return buildFiles ( inclusions ) ;
113+ }
114+
89115FixMe . prototype . runEngine = function ( ) {
90- // Check for existence of config.json, parse exclude paths if it exists
116+ var analysisFiles = [ ]
117+
91118 if ( fs . existsSync ( "/config.json" ) ) {
92119 var engineConfig = JSON . parse ( fs . readFileSync ( "/config.json" ) ) ;
93- var excludePaths = engineConfig . exclude_paths ;
94- } else {
95- var excludePaths = [ ] ;
96- }
97120
98- // Walk /code/ path and find files to analyze
99- var analysisFiles = fileWalk ( excludePaths ) ;
121+ if ( engineConfig . hasOwnProperty ( "include_paths" ) ) {
122+ analysisFiles = buildFilesWithInclusions ( engineConfig . include_paths ) ;
123+ } else if ( engineConfig . hasOwnProperty ( "exclude_paths" ) ) {
124+ analysisFiles = buildFilesWithExclusions ( engineConfig . exclude_paths ) ;
125+ }
126+ }
100127
128+ analysisFiles = filterFiles ( analysisFiles ) ;
101129 // Execute main loop and find fixmes in valid files
102130 analysisFiles . forEach ( function ( f , i , a ) {
103131 findFixmes ( f ) ;
0 commit comments