Skip to content

Commit 691a414

Browse files
committedNov 2, 2022
fix(require-returns-check): ensure breaks in final switch do not fulfill check for all branches returning
1 parent 5fcb62e commit 691a414

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed
 

‎README.md

+16
Original file line numberDiff line numberDiff line change
@@ -18321,6 +18321,22 @@ function maybeTrue() {
1832118321
return true;
1832218322
}
1832318323
}
18324+
18325+
/**
18326+
* @param {AST} astNode
18327+
* @returns {AST}
18328+
*/
18329+
const getTSFunctionComment = function (astNode) {
18330+
switch (greatGrandparent.type) {
18331+
case 'VariableDeclarator':
18332+
if (greatGreatGrandparent.type === 'VariableDeclaration') {
18333+
return greatGreatGrandparent;
18334+
}
18335+
18336+
default:
18337+
return astNode;
18338+
}
18339+
};
1832418340
````
1832518341

1832618342

‎src/utils/hasReturnValue.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ const allBrancheshaveReturnValues = (node, promFilter) => {
189189
case 'SwitchStatement': {
190190
return node.cases.every(
191191
(someCase) => {
192-
const nde = someCase.consequent.slice(-1)[0];
193-
return !nde || allBrancheshaveReturnValues(nde, promFilter);
192+
return !someCase.consequent.some((consNode) => {
193+
return consNode.type === 'BreakStatement' ||
194+
consNode.type === 'ReturnStatement' && consNode.argument === null;
195+
});
194196
},
195197
);
196198
}

‎test/rules/assertions/requireReturnsCheck.js

+19
Original file line numberDiff line numberDiff line change
@@ -1458,5 +1458,24 @@ export default {
14581458
},
14591459
},
14601460
},
1461+
{
1462+
code: `
1463+
/**
1464+
* @param {AST} astNode
1465+
* @returns {AST}
1466+
*/
1467+
const getTSFunctionComment = function (astNode) {
1468+
switch (greatGrandparent.type) {
1469+
case 'VariableDeclarator':
1470+
if (greatGreatGrandparent.type === 'VariableDeclaration') {
1471+
return greatGreatGrandparent;
1472+
}
1473+
1474+
default:
1475+
return astNode;
1476+
}
1477+
};
1478+
`,
1479+
},
14611480
],
14621481
};

0 commit comments

Comments
 (0)
Please sign in to comment.