@@ -45,33 +45,74 @@ function buildIssueJson(message, path) {
45
45
return JSON . stringify ( issue ) ;
46
46
}
47
47
48
- // Uses glob to traverse code directory and find files to analyze,
49
- // excluding files passed in with by CLI config, and including only
50
- // files in the list of desired extensions
51
- function fileWalk ( excludePaths , extensions ) {
52
- var analysisFiles = [ ] ;
53
- var allFiles = glob . sync ( "/code/**/**" , { } ) ;
54
-
55
- allFiles . forEach ( function ( file , i , a ) {
56
- if ( excludePaths . indexOf ( file . split ( "/code/" ) [ 1 ] ) < 0 ) {
57
- if ( ! fs . lstatSync ( file ) . isDirectory ( ) ) {
58
- var extension = "." + file . split ( "." ) . pop ( ) ;
59
-
60
- if ( extensions . indexOf ( extension ) >= 0 ) {
61
- analysisFiles . push ( file ) ;
48
+ function isFileWithMatchingExtension ( file , extensions ) {
49
+ var stats = fs . lstatSync ( file ) ;
50
+ var extension = "." + file . split ( "." ) . pop ( ) ;
51
+ return (
52
+ stats . isFile ( ) &&
53
+ ! stats . isSymbolicLink ( )
54
+ && extensions . indexOf ( extension ) >= 0
55
+ ) ;
56
+ }
57
+
58
+ function exclusionBasedFileListBuilder ( excludePaths ) {
59
+ // Uses glob to traverse code directory and find files to analyze,
60
+ // excluding files passed in with by CLI config, and including only
61
+ // files in the list of desired extensions.
62
+ //
63
+ // Deprecated style of file expansion, supported for users of the old CLI.
64
+ return function ( extensions ) {
65
+ var analysisFiles = [ ] ;
66
+ var allFiles = glob . sync ( "/code/**/**" , { } ) ;
67
+
68
+ allFiles . forEach ( function ( file , i , a ) {
69
+ if ( excludePaths . indexOf ( file . split ( "/code/" ) [ 1 ] ) < 0 ) {
70
+ if ( fs . lstatSync ( file ) . isFile ( ) ) {
71
+ if ( isFileWithMatchingExtension ( file ) ) {
72
+ analysisFiles . push ( file ) ;
73
+ }
62
74
}
63
75
}
64
- }
65
- } ) ;
76
+ } ) ;
77
+
78
+ return analysisFiles ;
79
+ } ;
80
+ }
66
81
67
- return analysisFiles ;
82
+ function inclusionBasedFileListBuilder ( includePaths ) {
83
+ // Uses glob to expand the files and directories in includePaths, filtering
84
+ // down to match the list of desired extensions.
85
+ return function ( extensions ) {
86
+ var analysisFiles = [ ] ;
87
+
88
+ includePaths . forEach ( function ( fileOrDirectory , i ) {
89
+ if ( ( / \/ $ / ) . test ( fileOrDirectory ) ) {
90
+ // if it ends in a slash, expand and push
91
+ var filesInThisDirectory = glob . sync (
92
+ "/code/" + fileOrDirectory + "/**/**"
93
+ ) ;
94
+ filesInThisDirectory . forEach ( function ( file , j ) {
95
+ if ( isFileWithMatchingExtension ( file , extensions ) ) {
96
+ analysisFiles . push ( file ) ;
97
+ }
98
+ } ) ;
99
+ } else {
100
+ // if not, check for ending in *.js
101
+ var fullPath = "/code/" + fileOrDirectory ;
102
+ if ( isFileWithMatchingExtension ( fullPath , extensions ) ) {
103
+ analysisFiles . push ( fullPath ) ;
104
+ }
105
+ }
106
+ } ) ;
107
+
108
+ return analysisFiles ;
109
+ } ;
68
110
}
69
111
70
112
var options = {
71
113
extensions : [ ".js" ] , ignore : true , reset : false , useEslintrc : true
72
114
} ;
73
- var ignores = [ ] ;
74
-
115
+ var buildFileList ;
75
116
runWithTiming ( "engineConfig" , function ( ) {
76
117
if ( fs . existsSync ( "/config.json" ) ) {
77
118
var engineConfig = JSON . parse ( fs . readFileSync ( "/config.json" ) ) ;
@@ -80,8 +121,16 @@ runWithTiming("engineConfig", function () {
80
121
options . configFile = "/code/" + engineConfig . config ;
81
122
}
82
123
83
- if ( engineConfig . exclude_paths ) {
84
- ignores = engineConfig . exclude_paths ;
124
+ if ( engineConfig . include_paths ) {
125
+ buildFileList = inclusionBasedFileListBuilder (
126
+ engineConfig . include_paths
127
+ ) ;
128
+ } else if ( engineConfig . exclude_paths ) {
129
+ var ignores = engineConfig . exclude_paths ;
130
+ buildFileList = exclusionBasedFileListBuilder ( ignores ) ;
131
+ } else {
132
+ // No includes or excludes, let's try with everything
133
+ buildFileList = exclusionBasedFileListBuilder ( [ ] ) ;
85
134
}
86
135
87
136
if ( engineConfig . extensions ) {
@@ -90,8 +139,10 @@ runWithTiming("engineConfig", function () {
90
139
}
91
140
} ) ;
92
141
93
- var analysisFiles = runWithTiming ( "fileWalk" , function ( ) { return fileWalk ( ignores , options . extensions ) ; } ) ,
94
- cli = runWithTiming ( "cliInit" , function ( ) { return new CLIEngine ( options ) ; } ) ,
142
+ var analysisFiles = runWithTiming ( "buildFileList" , function ( ) {
143
+ return buildFileList ( options . extensions ) ;
144
+ } ) ;
145
+ var cli = runWithTiming ( "cliInit" , function ( ) { return new CLIEngine ( options ) ; } ) ,
95
146
report = runWithTiming ( "cliRun" , function ( ) { return cli . executeOnFiles ( analysisFiles ) ; } ) ;
96
147
97
148
runWithTiming ( "resultsOutput" ,
0 commit comments