8000 Merge pull request #32 from codeclimate/jp/tidy-up · codeclimate/codeclimate-fixme@cf67428 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf67428

Browse files
committed
Merge pull request #32 from codeclimate/jp/tidy-up
Tidy up
2 parents 4ec360b + 21dd607 commit cf67428

File tree

6 files changed

+41
-156
lines changed

6 files changed

+41
-156
lines changed

lib/diff.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/file-builder.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/fix-me.js

Lines changed: 41 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
var glob = require('glob'),
2-
spawn = require('child_process').spawn,
3-
fs = require('fs'),
4-
path = require('path'),
5-
diff = require('./diff'),
6-
fileBuilder = require('./file-builder');
7-
8-
module.exports = FixMe;
9-
10-
function FixMe() { }
11-
12-
FixMe.prototype.runEngine = function(){
13-
var analysisFiles = [],
14-
config = {
15-
include_paths: ["./"],
16-
strings: ["FIXME", "TODO", "HACK", "XXX", "BUG"]
17-
},
18-
self = this;
1+
var fs = require('fs');
2+
var glob = require('glob');
3+
var path = require('path');
4+
var readline = require('readline');
5+
var spawn = require('child_process').spawn;
6+
7+
function FixMe() {}
8+
9+
FixMe.prototype.runEngine = function() {
10+
var config = {
11+
include_paths: ['./'],
12+
strings: ['FIXME', 'TODO', 'HACK', 'XXX', 'BUG']
13+
};
1914

2015
if (fs.existsSync('/config.json')) {
2116
var userConfig = JSON.parse(fs.readFileSync('/config.json'));
@@ -29,67 +24,40 @@ FixMe.prototype.runEngine = function(){
2924
}
3025
}
3126

32-
analysisFiles = fileBuilder.withIncludes(config.include_paths);
33-
analysisFiles = fileBuilder.filterFiles(analysisFiles);
34-
35-
self.find(analysisFiles, config.strings);
27+
this.find(config.include_paths, config.strings);
3628
}
3729

38-
FixMe.prototype.find = function(files, strings){
30+
FixMe.prototype.find = function(files, strings) {
3931
var fixmeStrings = '(' + strings.join('|') + ')';
40-
var grep = spawn('grep', ['-nHwoEr', fixmeStrings].concat(files));
41-
var output = "";
42-
var self = this;
43-
44-
grep.stdout.on('data', function(data) {
45-
output += data.toString();
46-
});
47-
48-
grep.stdout.on('close', function() {
49-
if (output !== ""){
50-
// Parses grep output
51-
var lines = output.split("\n");
52-
53-
lines.forEach(function(line, index, array){
54-
// grep spits out an extra line that we can ignore
55-
if (index < (array.length-1)) {
56-
// Grep output is colon delimited
57-
var cols = line.split(":");
58-
59-
// Remove remnants of container paths for external display
60-
var fileName = self.formatPath(cols[0]);
61-
var lineNum = cols[1];
62-
var matchedString = cols[2];
63-
64-
if (matchedString !== undefined){
65-
self.printIssue(fileName, parseInt(lineNum), matchedString);
32+
var args = ['--line-number', '--with-filename', '--word-regexp',
33+
'--only-matching', '--extended-regexp', '--recursive',
34+
'--binary-files=without-match', fixmeStrings];
35+
var grep = spawn('grep', args.concat(files));
36+
37+
readline.createInterface({ input: grep.stdout }).on('line', function(line) {
38+
var cols = line.split(':');
39+
var fileName = cols[0].replace(/^\/code\//, '');
40+
var lineNum = parseInt(cols[1]);
41+
var matchedString = cols[2];
42+
43+
if (matchedString !== undefined){
44+
var issue = JSON.stringify({
45+
'type': 'issue',
46+
'check_name': matchedString,
47+
'description': matchedString + ' found',
48+
'categories': ['Bug Risk'],
49+
'location':{
50+
'path': fileName,
51+
'lines': {
52+
'begin': lineNum,
53+
'end': lineNum
6654
}
6755
}
68-
})
69-
}
70-
});
71-
}
56+
});
7257

73-
FixMe.prototype.printIssue = function(fileName, lineNum, matchedString) {
74-
// Prints properly structured Issue data to STDOUT according to Code Climate Engine specification.
75-
var issue = {
76-
"type": "issue",
77-
"check_name": matchedString,
78-
"description": matchedString + " found",
79-
"categories": ["Bug Risk"],
80-
"location":{
81-
"path": fileName,
82-
"lines": {
83-
"begin": lineNum,
84-
"end": lineNum
85-
}
58+
console.log(issue + '\0');
8659
}
87-
};
88-
89-
var issueString = JSON.stringify(issue)+"\0";
90-
console.log(issueString);
60+
});
9161
}
9262

93-
FixMe.prototype.formatPath = function(path) {
94-
return path.replace(/^\/code\//, '');
95-
}
63+
module.exports = FixMe;

test/diff.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/file-builder.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/fix-me.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,4 @@ describe("fixMe", function(){
2828
}, 10);
2929
});
3030
});
31-
32-
describe('#formatPath(path)', function(){
33-
it('returns correct filename for files with /code in them', function(){
34-
var path = '/code/src/javascripts/code/test.js',
35-
formatted = engine.formatPath(path);
36-
37-
expect(formatted).to.eq('src/javascripts/code/test.js');
38-
});
39-
});
4031
});

0 commit comments

Comments
 (0)
0