Skip to content
Permalink
Browse files

Fix: Bug in no-extra-bind (fixes #4806)

  • Loading branch information...
mjomble committed Dec 26, 2015
1 parent 1ca6d56 commit b9bcbafb10ee95892d5d9a995e08880f00dbc2a5
Showing with 6 additions and 3 deletions.
  1. +4 −2 lib/rules/no-extra-bind.js
  2. +2 −1 tests/lib/rules/no-extra-bind.js
@@ -60,8 +60,10 @@ module.exports = function(context) {
var top = getTopScope(),
isArrowFunction = node.callee.type === "MemberExpression" && node.callee.object.type === "ArrowFunctionExpression";

if (top.call === node && (top.found === 0 || isArrowFunction)) {
context.report(node, "The function binding is unnecessary.");
if (top.call === node) {
if (top.found === 0 || isArrowFunction) {
context.report(node, "The function binding is unnecessary.");
}
scope.pop();
}
},
@@ -32,6 +32,7 @@ ruleTester.run("no-extra-bind", rule, {
{ code: "var a = (() => { return 1; }).bind(b)", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "The function binding is unnecessary.", type: "CallExpression"}] },
{ code: "var a = (() => { return this; }).bind(b)", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "The function binding is unnecessary.", type: "CallExpression"}] },
{ code: "var a = function() { (function(){ this.c }) }.bind(b)", errors: [{ message: "The function binding is unnecessary.", type: "CallExpression"}] },
{ code: "var a = function() { function c(){ this.d } }.bind(b)", errors: [{ message: "The function binding is unnecessary.", type: "CallExpression"}] }
{ code: "var a = function() { function c(){ this.d } }.bind(b)", errors: [{ message: "The function binding is unnecessary.", type: "CallExpression"}] },
{ code: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }.bind(b)", errors: [{ message: "The function binding is unnecessary.", type: "CallExpression", column: 9}] }
]
});

0 comments on commit b9bcbaf

Please sign in to comment.
You can’t perform that action at this time.