Skip to content

Commit

Permalink
fix: fix async generator bug (fixes #387)
Browse files Browse the repository at this point in the history
fix #386
  • Loading branch information
jedwards1211 authored and gajus committed Feb 15, 2019
1 parent 842e228 commit 5adb546
Show file tree
Hide file tree
Showing 3 changed files with 7,428 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/requireReturnType.js
Expand Up @@ -109,7 +109,7 @@ const create = (context) => {

const isArrow = functionNode.type === 'ArrowFunctionExpression';
const isArrowFunctionExpression = functionNode.expression;
const isFunctionReturnUndefined = !isArrowFunctionExpression && !(functionNode.generator && !functionNode.async) && (!targetNode.returnStatementNode || isUndefinedReturnType(targetNode.returnStatementNode));
const isFunctionReturnUndefined = !isArrowFunctionExpression && !functionNode.generator && (!targetNode.returnStatementNode || isUndefinedReturnType(targetNode.returnStatementNode));
const isReturnTypeAnnotationUndefined = getIsReturnTypeAnnotationUndefined(targetNode);

if (skipArrows === 'expressionsOnly' && isArrowFunctionExpression || skipArrows === true && isArrow || shouldFilterNode(functionNode)) {
Expand Down
46 changes: 46 additions & 0 deletions tests/rules/assertions/requireReturnType.js
Expand Up @@ -361,6 +361,34 @@ export default {
]
}
]
},
{
code: 'function * foo() { yield 2; }',
errors: [
{
message: 'Missing return type annotation.'
}
],
options: [
'always',
{
annotateUndefined: 'always'
}
]
},
{
code: 'async function * foo() { yield 2; }',
errors: [
{
message: 'Missing return type annotation.'
}
],
options: [
'always',
{
annotateUndefined: 'always'
}
]
}
],
misconfigured: [
Expand Down Expand Up @@ -860,6 +888,24 @@ export default {
]
}
]
},
{
code: 'function * foo(): Iterable<number> { yield 2; }',
options: [
'always',
{
annotateUndefined: 'always'
}
]
},
{
code: 'async function * foo(): AsyncIterable<number> { yield 2; }',
options: [
'always',
{
annotateUndefined: 'always'
}
]
}
]
};

0 comments on commit 5adb546

Please sign in to comment.