Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/fix-me.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var readline = require('readline');
var spawn = require('child_process').spawn;
var fs = require('fs');

var DEFAULT_PATHS = ['./'];
var DEFAULT_STRINGS = ['BUG', 'FIXME', 'HACK', 'TODO', 'XXX'];
Expand Down Expand Up @@ -35,6 +36,16 @@ FixMe.prototype.run = function(engineConfig) {
this.find(paths, strings);
};

var isItsOwnConfigFile = function(path) {
return path.indexOf(".codeclimate.yml") !== -1;
};

var isAYamlComment = function(path, lineNumber) {
var lines = fs.readFileSync(path, "utf8").split("\n");
var line = lines[lineNumber - 1] || "";
return line.match(/^\s*#/);
};

FixMe.prototype.find = function(paths, strings, callback) {
var pattern = `(${strings.join('|')})`;
var grep = spawn('grep', [...GREP_OPTIONS, pattern, ...paths]);
Expand All @@ -50,7 +61,7 @@ FixMe.prototype.find = function(paths, strings, callback) {
return;
}

if(path.indexOf('.codeclimate.yml') !== -1) { return; }
if(isItsOwnConfigFile(path) && !isAYamlComment(path, lineNumber)) { return; }

var issue = {
'categories': ['Bug Risk'],
Expand Down
9 changes: 6 additions & 3 deletions test/fix-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ describe("fixMe", function(){
engine.run(engineConfig);
});

it('ignores .codeclimate.yml', function(done) {
it('ignores .codeclimate.yml, except for comments', function(done) {
var buf = new IssueBuffer();
var engine = new FixMe(buf);

engine.find(['test/fixtures/'], ['URGENT'], function() {
var issues = buf.toIssues();
expect(issues.length).to.eq(1);
expect(issues[0].location.path).to.eq('test/fixtures/urgent.js');
expect(issues.length).to.eq(2);

expect(issues[0].location.path).to.eq('test/fixtures/.codeclimate.yml');
expect(issues[0].location.lines.begin).to.eq(2);
expect(issues[1].location.path).to.eq('test/fixtures/urgent.js');
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/.codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
engines:
# URGENT: enable duplication engine
fixme:
enabled: true
config:
Expand Down