Skip to content

Commit a47a1d2

Browse files
committed
Back off of execSync, would rather not rescue
1 parent 06d95aa commit a47a1d2

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

index.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
var glob = require('glob');
2-
var exec = require('child_process').execSync;
2+
var exec = require('child_process').exec;
33
var fs = require('fs');
44

55
module.exports = FixMe;
66
function FixMe() { }
77

88
// Strings to scan for in source
9-
var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)|?:'";
9+
var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)'";
1010

1111
// Prints properly structured Issue data to STDOUT according to
1212
// Code Climate Engine specification.
@@ -35,26 +35,29 @@ var findFixmes = function(file){
3535
var grepString = "grep -inHwoE " + fixmeStrings + " " + file;
3636

3737
// Execute grep with the FIXME patterns
38-
var results = exec(grepString);
38+
exec(grepString, function (error, stdout, stderr) {
39+
var results = stdout.toString();
3940

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");
4644

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(":");
4850

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];
5355

54-
printIssue(fileName, lineNum, matchedString);
56+
printIssue(fileName, lineNum, matchedString);
57+
}
58+
})
5559
}
5660
})
57-
5861
}
5962

6063
// Uses glob to traverse code directory and find files to analyze,
@@ -75,11 +78,17 @@ var fileWalk = function(excludePaths){
7578
}
7679

7780
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+
}
8089

8190
// Walk /code/ path and find files to analyze
82-
var analysisFiles = fileWalk(engineConfig.exclude_paths);
91+
var analysisFiles = fileWalk(excludePaths);
8392

8493
// Execute main loop and find fixmes in valid files
8594
analysisFiles.forEach(function(f, i, a){

0 commit comments

Comments
 (0)