1
1
var glob = require ( 'glob' ) ;
2
- var exec = require ( 'child_process' ) . execSync ;
2
+ var exec = require ( 'child_process' ) . exec ;
3
3
var fs = require ( 'fs' ) ;
4
4
5
5
module . exports = FixMe ;
6
6
function FixMe ( ) { }
7
7
8
8
// Strings to scan for in source
9
- var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)|?: '" ;
9
+ var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)'" ;
10
10
11
11
// Prints properly structured Issue data to STDOUT according to
12
12
// Code Climate Engine specification.
@@ -35,26 +35,29 @@ var findFixmes = function(file){
35
35
var grepString = "grep -inHwoE " + fixmeStrings + " " + file ;
36
36
37
37
// Execute grep with the FIXME patterns
38
- var results = exec ( grepString ) ;
38
+ exec ( grepString , function ( error , stdout , stderr ) {
39
+ var results = stdout . toString ( ) ;
39
40
40
- // Parses grep output
41
- var lines = results . toString ( ) . split ( "\n" ) ;
42
-
43
- lines . forEach ( function ( line , index , array ) {
44
- // grep spits out an extra line that we can ignore
45
- if ( index < ( array . length - 1 ) ) {
41
+ if ( results !== "" ) {
42
+ // Parses grep output
43
+ var lines = results . split ( "\n" ) ;
46
44
47
- var cols = line . split ( ":" ) ;
45
+ lines . forEach ( function ( line , index , array ) {
46
+ // grep spits out an extra line that we can ignore
47
+ if ( index < ( array . length - 1 ) ) {
48
+ // Grep output is colon delimited
49
+ var cols = line . split ( ":" ) ;
48
50
49
- // Remove remnants of container paths for external display
50
- var fileName = cols [ 0 ] . split ( "/code/" ) [ 1 ] ;
51
- var lineNum = cols [ 1 ] ;
52
- var matchedString = cols [ 2 ] ;
51
+ // Remove remnants of container paths for external display
52
+ var fileName = cols [ 0 ] . split ( "/code/" ) [ 1 ] ;
53
+ var lineNum = cols [ 1 ] ;
54
+ var matchedString = cols [ 2 ] ;
53
55
54
- printIssue ( fileName , lineNum , matchedString ) ;
56
+ printIssue ( fileName , lineNum , matchedString ) ;
57
+ }
58
+ } )
55
59
}
56
60
} )
57
-
58
61
}
59
62
60
63
// Uses glob to traverse code directory and find files to analyze,
@@ -75,11 +78,17 @@ var fileWalk = function(excludePaths){
75
78
}
76
79
77
80
FixMe . prototype . runEngine = function ( ) {
78
- // Pull engine config from env for exclude files
79
- var engineConfig = JSON . parse ( fs . readFileSync ( "/config.json" ) ) ;
81
+
82
+ // Check for existence of config.json, parse exclude paths if it exists
83
+ if ( fs . existsSync ( "/config.json" ) ) {
84
+ var engineConfig = JSON . parse ( fs . readFileSync ( "/config.json" ) ) ;
85
+ var excludePaths = engineConfig . exclude_paths ;
86
+ } else {
87
+ var excludePaths = [ ] ;
88
+ }
80
89
81
90
// Walk /code/ path and find files to analyze
82
- var analysisFiles = fileWalk ( engineConfig . exclude_paths ) ;
91
+ var analysisFiles = fileWalk ( excludePaths ) ;
83
92
84
93
// Execute main loop and find fixmes in valid files
85
94
analysisFiles . forEach ( function ( f , i , a ) {
0 commit comments