Skip to content

Commit 65e927b

Browse files
committedNov 24, 2022
fix(require-return-checks): check return statements prior to last line; fixes #935
1 parent 124d327 commit 65e927b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
 

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -18392,6 +18392,17 @@ const f =
1839218392
() => {
1839318393
return function () {};
1839418394
};
18395+
18396+
/**
18397+
* Description.
18398+
*
18399+
* @returns Result.
18400+
*/
18401+
export function f(): string {
18402+
return "";
18403+
18404+
interface I {}
18405+
}
1839518406
````
1839618407

1839718408

‎src/utils/hasReturnValue.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ const allBrancheshaveReturnValues = (node, promFilter) => {
139139
case 'FunctionDeclaration':
140140
case 'ArrowFunctionExpression': {
141141
return node.expression && (!isNewPromiseExpression(node.body) || !isVoidPromise(node.body)) ||
142-
allBrancheshaveReturnValues(node.body, promFilter);
142+
allBrancheshaveReturnValues(node.body, promFilter) || node.body.body.some((nde) => {
143+
return nde.type === 'ReturnStatement';
144+
});
143145
}
144146

145147
case 'BlockStatement': {

‎test/rules/assertions/requireReturnsCheck.js

+15
Original file line numberDiff line numberDiff line change
@@ -1490,5 +1490,20 @@ export default {
14901490
};
14911491
`,
14921492
},
1493+
{
1494+
code: `
1495+
/**
1496+
* Description.
1497+
*
1498+
* @returns Result.
1499+
*/
1500+
export function f(): string {
1501+
return "";
1502+
1503+
interface I {}
1504+
}
1505+
`,
1506+
parser: require.resolve('@typescript-eslint/parser'),
1507+
},
14931508
],
14941509
};

0 commit comments

Comments
 (0)
Please sign in to comment.