Skip to content

Commit

Permalink
change rule prefer-invoke to prefer-invoke-map
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimomer committed Jan 25, 2016
1 parent 0acfdc8 commit 90d057c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions docs/rules/prefer-invoke.md → docs/rules/prefer-invoke-map.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prefer invoke

When using `_.map` with a method call of each item in the collection, it could improve readability by switching to `_.invoke`
When using `_.map` with a method call of each item in the collection, it could improve readability by switching to `_.invokeMap`

## Rule Details

Expand All @@ -19,12 +19,12 @@ The following patterns are not considered warnings:

```js

var x = _.invoke(arr, 'f');
var x = _.invokeMap(arr, 'f');

var x = _.invoke(collection, 'split', ':');
var x = _.invokeMap(collection, 'split', ':');
```


## When Not To Use It

If you do not want to enforce using `_.invoke`, and prefer using `_.map` with a method call instead.
##### This rule is only relevant for Lodash 4. If you don't use Lodash 4, you should not use this rule.
If you do not want to enforce using `_.invokeMap`, and prefer using `_.map` with a method call instead.
4 changes: 2 additions & 2 deletions lib/rules/prefer-invoke.js → lib/rules/prefer-invoke-map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview Rule to check if a call to map should be a call to invoke
* @fileoverview Rule to check if a call to map should be a call to invokeMap
*/
'use strict';

Expand All @@ -18,7 +18,7 @@ module.exports = function (context) {
return {
CallExpression: lodashUtil.getLodashMethodVisitor(settings, function (node, iteratee) {
if (lodashUtil.isCallToMethod(node, settings.version, 'map') && isFunctionMethodCallOfParam(iteratee)) {
context.report(node, 'Prefer _.invoke over map to a method call.');
context.report(node, 'Prefer _.invokeMap over map to a method call.');
}
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
// Requirements
// ------------------------------------------------------------------------------

var rule = require('../../../lib/rules/prefer-invoke');
var rule = require('../../../lib/rules/prefer-invoke-map');
var RuleTester = require('eslint').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

var ruleTester = new RuleTester();
var errors = [{message: 'Prefer _.invoke over map to a method call.'}];
ruleTester.run('prefer-invoke', rule, {
var errors = [{message: 'Prefer _.invokeMap over map to a method call.'}];
ruleTester.run('prefer-invoke-map', rule, {
valid: [
'var x = _.invoke(arr, "f")',
'var x = _.invoke(arr, "split", " ")'
'var x = _.invokeMap(arr, "f")',
'var x = _.invokeMap(arr, "split", " ")'
],
invalid: [{
code: '_.map(a, function(x) {return x.f()});',
Expand Down

0 comments on commit 90d057c

Please sign in to comment.