eslint-plugin-mocha
eslint-plugin-mocha copied to clipboard
handle-done-callback: allow passing done as callback
this should not cause an error:
it('should not cause an error', function(done) {
var obj = {someFunc: done};
somethingThatCallsSomeFuncOnObj(obj);
});
should it?
Yes, I think you are right.
The current implementation explicitly checks for a CallExpression of done or its direct parent, so passing done to a function should work but not if it is nested in other expressions like an object literal.
Maybe we should just relax the rule and treat any read of the done callback as "handled".
What do you think @jfmengels?
I agree with you, the code excerpt should not cause an error.
We do lose the "assurance" that the function is at least called at some point in the code, but that did not make sure that the callback was correctly triggered anyway. Just checking the presence of an Identifier with the same name as the callback would be fine IMO.
Wouldn't that then just be a very specific version of no-unused-vars, which is in eslint:recommend?