coffeelint-multiple-callback
Version:
Coffeelint rule that checks for callbacks being called multiple times
38 lines (28 loc) • 1.56 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var ForkLinter, MultipleCallback, _;
_ = require('lodash');
ForkLinter = require('./ForkLinter');
module.exports = MultipleCallback = (function() {
function MultipleCallback() {}
MultipleCallback.prototype.rule = {
name: 'multiple_callback',
level: 'error',
message: 'Callback has the potential of being called multiple times',
description: 'CoffeeLint rule that finds instances where callbacks might be called more than once or not at all.\n\nThese functions have the potential of calling cb() multiple times, and is likely an error:\n\n badFunc = (err, cb)->\n cb err\n cb err # BAD\n return\n\n\n badIf = (err, cb)->\n if err\n cb err\n\n cb null # BAD\n return\n\n\nThese functions are okay, since they only call the callback once no matter how the logic runs:\n\n goodIf = (err, cb)->\n if err\n cb err\n else\n cb null\n return\n\n\n goodIf2 = (err, cb)->\n if err\n cb err\n return\n\n cb null\n return\n'
};
MultipleCallback.prototype.lintAST = function(root_node, astApi) {
var err, fork_linter, i, len, ref;
this.astApi = astApi;
fork_linter = new ForkLinter();
fork_linter.lint(root_node);
ref = fork_linter.errors;
for (i = 0, len = ref.length; i < len; i++) {
err = ref[i];
this.errors.push(this.astApi.createError(err));
}
};
return MultipleCallback;
})();
}).call(this);
//# sourceMappingURL=index.js.map