Skip to content

Commit

Permalink
fix(require-return-checks): check return statements prior to last l…
Browse files Browse the repository at this point in the history
…ine; fixes #935
  • Loading branch information
brettz9 committed Nov 24, 2022
1 parent 124d327 commit 65e927b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -18392,6 +18392,17 @@ const f =
() => {
return function () {};
};

/**
* Description.
*
* @returns Result.
*/
export function f(): string {
return "";

interface I {}
}
````


Expand Down
4 changes: 3 additions & 1 deletion src/utils/hasReturnValue.js
Expand Up @@ -139,7 +139,9 @@ const allBrancheshaveReturnValues = (node, promFilter) => {
case 'FunctionDeclaration':
case 'ArrowFunctionExpression': {
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node.body)) ||
allBrancheshaveReturnValues(node.body, promFilter);
allBrancheshaveReturnValues(node.body, promFilter) || node.body.body.some((nde) => {
return nde.type === 'ReturnStatement';
});
}

case 'BlockStatement': {
Expand Down
15 changes: 15 additions & 0 deletions test/rules/assertions/requireReturnsCheck.js
Expand Up @@ -1490,5 +1490,20 @@ export default {
};
`,
},
{
code: `
/**
* Description.
*
* @returns Result.
*/
export function f(): string {
return "";
interface I {}
}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
};

0 comments on commit 65e927b

Please sign in to comment.