Skip to content

Commit 521d380

Browse files
committed
Merge pull request #5 from codeclimate/exclude_image_files
Fixes bugs when binary files are scanned
2 parents a1a3ca6 + 8731c51 commit 521d380

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
var glob = require('glob');
22
var exec = require('child_process').exec;
33
var fs = require('fs');
4+
var path = require('path');
45

56
module.exports = FixMe;
67
function FixMe() { }
78

89
// Strings to scan for in source
910
var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)'";
1011

12+
var excludeExtensions = [".jpg", ".jpeg", ".png", ".gif"];
13+
1114
// Prints properly structured Issue data to STDOUT according to
1215
// Code Climate Engine specification.
1316
var printIssue = function(fileName, lineNum, matchedString){
@@ -53,32 +56,37 @@ var findFixmes = function(file){
5356
var lineNum = cols[1];
5457
var matchedString = cols[2];
5558

56-
printIssue(fileName, lineNum, matchedString);
59+
if (matchedString !== undefined){
60+
printIssue(fileName, lineNum, matchedString);
61+
}
5762
}
5863
})
5964
}
6065
})
6166
}
6267

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)
72+
}
73+
6374
// Uses glob to traverse code directory and find files to analyze,
6475
// excluding files passed in with by CLI config
6576
var fileWalk = function(excludePaths){
6677
var analysisFiles = [];
6778
var allFiles = glob.sync("/code/**/**", {});
6879

6980
allFiles.forEach(function(file, i, a){
70-
if(excludePaths.indexOf(file.split("/code/")[1]) < 0) {
71-
if(!fs.lstatSync(file).isDirectory()){
72-
analysisFiles.push(file);
73-
}
81+
if(eligibleFile(file, excludePaths)){
82+
analysisFiles.push(file);
7483
}
7584
});
7685

7786
return analysisFiles;
7887
}
7988

8089
FixMe.prototype.runEngine = function(){
81-
8290
// Check for existence of config.json, parse exclude paths if it exists
8391
if (fs.existsSync("/config.json")) {
8492
var engineConfig = JSON.parse(fs.readFileSync("/config.json"));

0 commit comments

Comments
 (0)