Skip to content

Commit

Permalink
fix bug in prefer-times where it works on native-map
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimomer committed Nov 22, 2015
1 parent b064156 commit dec6a1f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rules/prefer-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function (context) {
}

function handleFunctionExpression(node) {
if (lodashUtil.isCallToMethod(node.parent, 'map')) {
if (lodashUtil.isCallToMethod(node.parent, 'map') && (lodashUtil.isLodashCall(node.parent) || lodashUtil.isLodashWrapper(node.parent))) {
callStack.push({func: node, params: _.map(node.params, getParamName), anyUsed: false});
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/rules/prefer-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ ruleTester.run('prefer-times', rule, {
'_.forEach(arr, function() {f(g(r)); })',
'var results = _.times(arr.length, function() {return Math.random();})',
'var x = _.map(a, "prop");',
'var x = _.map(arr, function(a) {return _.map(a, function(b) {return b + 1});});'
],
'var x = _.map(arr, function(a) {return _.map(a, function(b) {return b + 1});});',
"var x = arr.map(function () {return str; }).join('')"
],
invalid: [{
code: '_(arr).map(function(){return g}).value()',
errors: errors
Expand Down

0 comments on commit dec6a1f

Please sign in to comment.