@coffeelint/cli
Version:
Lint your CoffeeScript
67 lines (57 loc) • 1.72 kB
JavaScript
(function() {
var NoEmptyFunctions, isEmptyCode;
isEmptyCode = function(node, astApi) {
var nodeName;
nodeName = astApi.getNodeName(node);
return nodeName === 'Code' && node.body.isEmpty();
};
module.exports = NoEmptyFunctions = (function() {
class NoEmptyFunctions {
lintAST(node, astApi) {
this.lintNode(node, astApi);
return void 0;
}
lintNode(node, astApi) {
var error;
if (isEmptyCode(node, astApi)) {
error = astApi.createError({
lineNumber: node.locationData.first_line + 1,
columnNumber: node.locationData.first_column + 1
});
this.errors.push(error);
}
return node.eachChild((child) => {
return this.lintNode(child, astApi);
});
}
};
NoEmptyFunctions.prototype.rule = {
type: 'problem',
name: 'no_empty_functions',
level: 'ignore',
message: 'Empty function',
description: `Disallows declaring empty functions. The goal of this rule is that
unintentional empty callbacks can be detected:
<pre>
<code>someFunctionWithCallback ->
doSomethingSignificant()
</code>
</pre>
The problem is that the call to
<tt>doSomethingSignificant</tt> will be made regardless
of <tt>someFunctionWithCallback</tt>'s execution. It can
be because you did not indent the call to
<tt>doSomethingSignificant</tt> properly.
If you really meant that <tt>someFunctionWithCallback</tt>
should call a callback that does nothing, you can write your code
this way:
<pre>
<code>someFunctionWithCallback ->
undefined
doSomethingSignificant()
</code>
</pre>`
};
return NoEmptyFunctions;
}).call(this);
}).call(this);