Skip to content

Commit

Permalink
Treat generator functions as returning a value for collection-return
Browse files Browse the repository at this point in the history
  • Loading branch information
pkaminski authored and ganimomer committed Jan 22, 2018
1 parent 5843661 commit 19079ef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/collection-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
'CallExpression:exit': getLodashMethodCallExpVisitor(lodashContext, (node, iteratee, {method, version}) => {
if (isCollectionMethod(version, method) && funcInfos.has(iteratee)) {
const {hasReturn} = funcInfos.get(iteratee)
if (isFunctionDefinitionWithBlock(iteratee) && !hasReturn && !iteratee.async) {
if (isFunctionDefinitionWithBlock(iteratee) && !hasReturn && !iteratee.async && !iteratee.generator) {
context.report({node, message: `Do not use _.${method} without returning a value`})
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/collection-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ruleTester.run('collection-return', rule, {
'function x(a) {return a;}',
'y = _.reject(x, p => p); _.forEach(t, s => {}).value();',
'_.map(a, x => f(x).then(() => {g()}))',
{code: '_.map(x, async t => {})', parserOptions: {ecmaVersion: 8}}
{code: '_.map(x, async t => {})', parserOptions: {ecmaVersion: 8}},
{code: '_.map(x, function*(t) {})', parserOptions: {ecmaVersion: 6}}
].map(withDefaultPragma),
invalid: [{
code: '_.map(arr, function(a) {console.log(a)})',
Expand Down

0 comments on commit 19079ef

Please sign in to comment.