@@ -23,7 +23,7 @@ var printIssue = function(fileName, lineNum, matchedString){
23
23
"path" : fileName ,
24
24
"lines" : {
25
25
"begin" : lineNum ,
26
- "end" : lineNum
26
+ "end" : lineNum
27
27
}
28
28
}
29
29
} ;
@@ -44,7 +44,7 @@ var findFixmes = function(file){
44
44
if ( results !== "" ) {
45
45
// Parses grep output
46
46
var lines = results . split ( "\n" ) ;
47
-
47
+
48
48
lines . forEach ( function ( line , index , array ) {
49
49
// grep spits out an extra line that we can ignore
50
50
if ( index < ( array . length - 1 ) ) {
@@ -65,39 +65,65 @@ var findFixmes = function(file){
65
65
} )
66
66
}
67
67
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 ;
72
79
}
73
80
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 = [ ] ;
79
84
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 ( ) ;
84
97
} ) ;
85
-
86
- return analysisFiles ;
98
+ }
99
+
100
+ // Returns file paths based on the exclude_paths values in config file
101
+ var buildFilesWithExclusions = function ( exclusions ) {
102
+ var allFiles = glob . sync ( "/code/**/**" , { } ) ;
103
+ var excludedFiles = buildFiles ( exclusions ) ;
104
+
105
+ return diff ( allFiles , excludedFiles ) ;
106
+ }
107
+
108
+ // Returns file paths based on the include_paths values in config file
109
+ var buildFilesWithInclusions = function ( inclusions ) {
110
+ return buildFiles ( inclusions ) ;
87
111
}
88
112
89
113
FixMe . prototype . runEngine = function ( ) {
90
- // Check for existence of config.json, parse exclude paths if it exists
114
+ var analysisFiles = [ ]
115
+
91
116
if ( fs . existsSync ( "/config.json" ) ) {
92
117
var engineConfig = JSON . parse ( fs . readFileSync ( "/config.json" ) ) ;
93
- var excludePaths = engineConfig . exclude_paths ;
94
- } else {
95
- var excludePaths = [ ] ;
96
- }
97
118
98
- // Walk /code/ path and find files to analyze
99
- var analysisFiles = fileWalk ( excludePaths ) ;
119
+ if ( engineConfig . hasOwnProperty ( "include_paths" ) ) {
120
+ analysisFiles = buildFilesWithInclusions ( engineConfig . include_paths ) ;
121
+ } else if ( engineConfig . hasOwnProperty ( "exclude_paths" ) ) {
122
+ analysisFiles = buildFilesWithExclusions ( engineConfig . exclude_paths ) ;
123
+ }
124
+ }
100
125
126
+ analysisFiles = filterFiles ( analysisFiles ) ;
101
127
// Execute main loop and find fixmes in valid files
102
128
analysisFiles . forEach ( function ( f , i , a ) {
103
129
findFixmes ( f ) ;
0 commit comments