8000 Tidy up · codeclimate/codeclimate-fixme@d05aae3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d05aae3

Browse files
committed
Tidy up
* Remove unnecessary workspace fiddling * Delete unused array diff function * Remove pending tests * Consistency changes (spacing, quoting) * Split up var declarations
1 parent df1a1e4 commit d05aae3

File tree

6 files changed

+39
-138
lines changed

6 files changed

+39
-138
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: 39 additions & 58 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 glob = require('glob');
2+
var spawn = require('child_process').spawn;
3+
var fs = require('fs');
4+
var path = require('path');
5+
6+
function FixMe() {}
7+
8+
FixMe.prototype.runEngine = function() {
9+
var analysisFiles = [];
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,64 +24,50 @@ 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('|') + ')';
4032
var grep = spawn('grep', ['-nHwoEr', fixmeStrings].concat(files));
4133
var self = this;
4234

4335
grep.stdout.on('data', function (data) {
44-
var results = data.toString();
45-
46-
if (results !== ""){
47-
// Parses grep output
48-
var lines = results.split("\n");
36+
var lines = data.toString().split('\n');
4937

50-
lines.forEach(function(line, index, array){
51-
// grep spits out an extra line that we can ignore
52-
if (index < (array.length-1)) {
53-
// Grep output is colon delimited
54-
var cols = line.split(":");
38+
lines.forEach(function(line) {
39+
var cols = line.split(':');
40+
var fileName = self.formatPath(cols[0]);
41+
var lineNum = cols[1];
42+
var matchedString = cols[2];
5543

56-
// Remove remnants of container paths for external display
57-
var fileName = self.formatPath(cols[0]);
58-
var lineNum = cols[1];
59-
var matchedString = cols[2];
60-
61-
if (matchedString !== undefined){
62-
self.printIssue(fileName, parseInt(lineNum), matchedString);
63-
}
64-
}
65-
})
66-
}
44+
if (matchedString !== undefined) {
45+
self.printIssue(fileName, parseInt(lineNum), matchedString);
46+
}
47+
});
6748
});
6849
}
6950

7051
FixMe.prototype.printIssue = function(fileName, lineNum, matchedString) {
71-
// Prints properly structured Issue data to STDOUT according to Code Climate Engine specification.
72-
var issue = {
73-
"type": "issue",
74-
"check_name": matchedString,
75-
"description": matchedString + " found",
76-
"categories": ["Bug Risk"],
77-
"location":{
78-
"path": fileName,
79-
"lines": {
80-
"begin": lineNum,
81-
"end": lineNum
52+
var issue = JSON.stringify({
53+
'type': 'issue',
54+
'check_name': matchedString,
55+
'description': matchedString + ' found',
56+
'categories': ['Bug Risk'],
57+
'location': {
58+
'path': fileName,
59+
'lines': {
60+
'begin': lineNum,
61+
'end': lineNum
8262
}
8363
}
84-
};
64+
});
8565

86-
var issueString = JSON.stringify(issue)+"\0";
87-
console.log(issueString);
66+
console.log(issue+'\0');
8867
}
8968

9069
FixMe.prototype.formatPath = function(path) {
9170
return path.replace(/^\/code\//, '');
9271
}
72+
73+
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ var expect = require('chai').expect,
44
engine = new fixMe;
55

66
describe("fixMe", function(){
7-
describe("#runEngine()", function(){
8-
xit("checks for /config.json", function(){
9-
// expect();
10-
});
11-
});
12-
137
describe('#find(file)', function(){
148
it('finds and correctly prints TODO issues', function(done){
159
var capturedText = "",

0 commit comments

Comments
 (0)
0