Skip to content

Fixes bugs when binary files are scanned #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
var glob = require('glob');
var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');

module.exports = FixMe;
function FixMe() { }

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

var excludeExtensions = [".jpg", ".jpeg", ".png", ".gif"];

// Prints properly structured Issue data to STDOUT according to
// Code Climate Engine specification.
var printIssue = function(fileName, lineNum, matchedString){
Expand Down Expand Up @@ -53,32 +56,37 @@ var findFixmes = function(file){
var lineNum = cols[1];
var matchedString = cols[2];

printIssue(fileName, lineNum, matchedString);
if (matchedString !== undefined){
printIssue(fileName, lineNum, matchedString);
}
}
})
}
})
}

var eligibleFile = function(fp, excludePaths){
return (excludePaths.indexOf(fp.split("/code/")[1]) < 0) &&
!fs.lstatSync(fp).isDirectory() &&
(excludeExtensions.indexOf(path.extname(fp)) < 0)
}

// Uses glob to traverse code directory and find files to analyze,
// excluding files passed in with by CLI config
var fileWalk = function(excludePaths){
var analysisFiles = [];
var allFiles = glob.sync("/code/**/**", {});

allFiles.forEach(function(file, i, a){
if(excludePaths.indexOf(file.split("/code/")[1]) < 0) {
if(!fs.lstatSync(file).isDirectory()){
analysisFiles.push(file);
}
if(eligibleFile(file, excludePaths)){
analysisFiles.push(file);
}
});

return analysisFiles;
}

FixMe.prototype.runEngine = function(){

// Check for existence of config.json, parse exclude paths if it exists
if (fs.existsSync("/config.json")) {
var engineConfig = JSON.parse(fs.readFileSync("/config.json"));
Expand Down