|
1 | 1 | var glob = require('glob');
|
2 | 2 | var exec = require('child_process').exec;
|
3 | 3 | var fs = require('fs');
|
| 4 | +var path = require('path'); |
4 | 5 |
|
5 | 6 | module.exports = FixMe;
|
6 | 7 | function FixMe() { }
|
7 | 8 |
|
8 | 9 | // Strings to scan for in source
|
9 | 10 | var fixmeStrings = "'(FIXME|TODO|HACK|XXX|BUG)'";
|
10 | 11 |
|
| 12 | +var excludeExtensions = [".jpg", ".jpeg", ".png", ".gif"]; |
| 13 | + |
11 | 14 | // Prints properly structured Issue data to STDOUT according to
|
12 | 15 | // Code Climate Engine specification.
|
13 | 16 | var printIssue = function(fileName, lineNum, matchedString){
|
@@ -53,32 +56,37 @@ var findFixmes = function(file){
|
53 | 56 | var lineNum = cols[1];
|
54 | 57 | var matchedString = cols[2];
|
55 | 58 |
|
56 |
| - printIssue(fileName, lineNum, matchedString); |
| 59 | + if (matchedString !== undefined){ |
| 60 | + printIssue(fileName, lineNum, matchedString); |
| 61 | + } |
57 | 62 | }
|
58 | 63 | })
|
59 | 64 | }
|
60 | 65 | })
|
61 | 66 | }
|
62 | 67 |
|
| 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 | + |
63 | 74 | // Uses glob to traverse code directory and find files to analyze,
|
64 | 75 | // excluding files passed in with by CLI config
|
65 | 76 | var fileWalk = function(excludePaths){
|
66 | 77 | var analysisFiles = [];
|
67 | 78 | var allFiles = glob.sync("/code/**/**", {});
|
68 | 79 |
|
69 | 80 | 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); |
74 | 83 | }
|
75 | 84 | });
|
76 | 85 |
|
77 | 86 | return analysisFiles;
|
78 | 87 | }
|
79 | 88 |
|
80 | 89 | FixMe.prototype.runEngine = function(){
|
81 |
| - |
82 | 90 | // Check for existence of config.json, parse exclude paths if it exists
|
83 | 91 | if (fs.existsSync("/config.json")) {
|
84 | 92 | var engineConfig = JSON.parse(fs.readFileSync("/config.json"));
|
|
0 commit comments