eslint-plugin-mocha icon indicating copy to clipboard operation
eslint-plugin-mocha copied to clipboard

handle-done-callback: allow passing done as callback

Open shaharmor opened this issue 8 years ago • 3 comments

this should not cause an error:

it('should not cause an error', function(done) {
  var obj = {someFunc: done};
  somethingThatCallsSomeFuncOnObj(obj);
});

should it?

shaharmor avatar Dec 14 '16 12:12 shaharmor

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?

lo1tuma avatar Dec 23 '16 15:12 lo1tuma

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.

jfmengels avatar Dec 23 '16 15:12 jfmengels

Wouldn't that then just be a very specific version of no-unused-vars, which is in eslint:recommend?

edg2s avatar May 27 '20 23:05 edg2s