Repository: lo1tuma/eslint-plugin-mocha (ts)

Issue:
handle-done-callback: Add checks how the callback is handled specifically (e.g. for simple to detect erroneous calls)
E.g. `return done;` should cause a warning while `return otherImportantFunctionThatHandlesDone(done);` should not.

Pull request description:
Improve detection if done callback is handled
Fixes #20

Patch:
diff --git a/lib/rules/handle-done-callback.js b/lib/rules/handle-done-callback.js
index 84e1359..eb9a123 100644
--- a/lib/rules/handle-done-callback.js
+++ b/lib/rules/handle-done-callback.js
@@ -43,13 +43,23 @@ module.exports = function (context) {
         });
     }
 
+    function isReferenceHandled(reference) {
+        var parent = context.getNodeByRangeIndex(reference.identifier.range[0]).parent;
+
+        return parent.type === 'CallExpression';
+    }
+
+    function hasHandledReferences(references) {
+        return references.some(isReferenceHandled);
+    }
+
     function checkAsyncMochaFunction(functionExpression) {
         var scope = context.getScope(),
             callback = functionExpression.params[0],
             callbackName = callback.name,
             callbackVariable = findParamInScope(callbackName, scope);
 
-        if (callbackVariable && callbackVariable.references.length === 0) {
+        if (callbackVariable && !hasHandledReferences(callbackVariable.references)) {
             context.report(callback, 'Expected "{{name}}" callback to be handled.', { name: callbackName });
         }
     }


Test patch:
diff --git a/test/rules/handle-done-callback.js b/test/rules/handle-done-callback.js
index fb80cfd..9757882 100644
--- a/test/rules/handle-done-callback.js
+++ b/test/rules/handle-done-callback.js
@@ -83,6 +83,18 @@ ruleTester.run('handle-done-callback', rules['handle-done-callback'], {
             code: 'it("", (done) => { });',
             ecmaFeatures: { arrowFunctions: true },
             errors: [ { message: 'Expected "done" callback to be handled.', column: 9, line: 1 } ]
+        },
+        {
+            code: 'it("", function (done) { return done; });',
+            errors: [ { message: 'Expected "done" callback to be handled.', column: 18, line: 1 } ]
+        },
+        {
+            code: 'it("", function (done) { done; });',
+            errors: [ { message: 'Expected "done" callback to be handled.', column: 18, line: 1 } ]
+        },
+        {
+            code: 'it("", function (done) { var foo = done; });',
+            errors: [ { message: 'Expected "done" callback to be handled.', column: 18, line: 1 } ]
         }
     ]
 });