Skip to content

Commit

Permalink
fix error in callback-binding in methods without callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimomer committed Jan 26, 2016
1 parent 599e8e7 commit c985ba9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/callback-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (context) {
4: function (node, iteratee) {
var isTransformerMethod = transformerMethods.some(lodashUtil.isCallToMethod.bind(null, node, settings.version));
var iterateeIndex = node.arguments.indexOf(iteratee);
if ((isTransformerMethod && node.arguments[iterateeIndex + 2]) || (!isTransformerMethod && node.arguments[iterateeIndex + 1])) {
if (iterateeIndex !== -1 && (isTransformerMethod && node.arguments[iterateeIndex + 2] || (!isTransformerMethod && node.arguments[iterateeIndex + 1]))) {
context.report(iteratee, 'Do not use Lodash 3 thisArg, use binding instead');
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/callback-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ ruleTester.run('callback-binding', rule, {
'var r = _.find(arr, function (i) { return this.x; }.bind(this, x));'
].map(optionsUtil.fromVersion3).concat([
'var x = _.map(arr, f.bind(this))',
'var x = _.find(users, function(user) { return user.age > this.age}.bind(this));'
'var x = _.find(users, function(user) { return user.age > this.age}.bind(this));',
'var t = _.isArray(x)'
]),
invalid: [
'var r = _.find(users, function (user) { return user.age > this.age; }.bind(this));',
Expand Down

0 comments on commit c985ba9

Please sign in to comment.