Skip to content

Commit

Permalink
fix(require-returns-check): ensure breaks in final switch do not fu…
Browse files Browse the repository at this point in the history
…lfill check for all branches returning
  • Loading branch information
brettz9 committed Nov 2, 2022
1 parent 5fcb62e commit 691a414
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -18321,6 +18321,22 @@ function maybeTrue() {
return true;
}
}

/**
* @param {AST} astNode
* @returns {AST}
*/
const getTSFunctionComment = function (astNode) {
switch (greatGrandparent.type) {
case 'VariableDeclarator':
if (greatGreatGrandparent.type === 'VariableDeclaration') {
return greatGreatGrandparent;
}

default:
return astNode;
}
};
````


Expand Down
6 changes: 4 additions & 2 deletions src/utils/hasReturnValue.js
Expand Up @@ -189,8 +189,10 @@ const allBrancheshaveReturnValues = (node, promFilter) => {
case 'SwitchStatement': {
return node.cases.every(
(someCase) => {
const nde = someCase.consequent.slice(-1)[0];
return !nde || allBrancheshaveReturnValues(nde, promFilter);
return !someCase.consequent.some((consNode) => {
return consNode.type === 'BreakStatement' ||
consNode.type === 'ReturnStatement' && consNode.argument === null;
});
},
);
}
Expand Down
19 changes: 19 additions & 0 deletions test/rules/assertions/requireReturnsCheck.js
Expand Up @@ -1458,5 +1458,24 @@ export default {
},
},
},
{
code: `
/**
* @param {AST} astNode
* @returns {AST}
*/
const getTSFunctionComment = function (astNode) {
switch (greatGrandparent.type) {
case 'VariableDeclarator':
if (greatGreatGrandparent.type === 'VariableDeclaration') {
return greatGreatGrandparent;
}
default:
return astNode;
}
};
`,
},
],
};

0 comments on commit 691a414

Please sign in to comment.