Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Only fail build on errors and allow lower severities to pass #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion complexity.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cyclomatic": 3,
"halstead": 8,
"maintainability": 100,
"broadcast": false
"broadcast": false,
"allowWarnings": true
}
}
9 changes: 7 additions & 2 deletions tasks/complexity.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = function(grunt) {
cyclomatic: [3, 7, 12],
halstead: [8, 13, 20],
maintainability: 100,
hideComplexFunctions: false
hideComplexFunctions: false,
allowWarnings: false
},

normalizeOptions: function(options) {
Expand Down Expand Up @@ -117,7 +118,11 @@ module.exports = function(grunt) {
}, this);
}

grunt.fail.errorcount += complicatedFunctions.length;
var errors = complicatedFunctions.filter(function(data){
return data.severity === "error";
});

grunt.fail.errorcount += (options.allowWarnings ? errors.length : complicatedFunctions.length);

reporter.complexity(filepath, complicatedFunctions);

Expand Down
12 changes: 6 additions & 6 deletions test/eventReporter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ describe('Event Reporter', function() {

it ('triggers a maintainability event', function(done) {
var targetFile = __dirname + '/fixtures/sample.js';
var reporter = Complexity.buildReporter([targetFile], { broadcast: true })
var reporter = Complexity.buildReporter([targetFile], { broadcast: true });

grunt.event.on('grunt-complexity.maintainability', function(report) {
expect(report.filepath).to.equal(targetFile)
expect(report.valid).to.equal(true)
done()
})
expect(report.filepath).to.equal(targetFile);
expect(report.valid).to.equal(true);
done();
});

Complexity.analyze(reporter, [targetFile], Complexity.normalizeOptions({
maintainability: 0
}))
}));
});
});