lib/rules/no-useless-return.js
function getUselessReturns(uselessReturns, prevSegments, providedTraversedSegments) {
            const traversedSegments = providedTraversedSegments || new WeakSet();

            for (const segment of prevSegments) {
                if (!segment.reachable) {
                    if (!traversedSegments.has(segment)) {
                        traversedSegments.add(segment);
                        getUselessReturns(
                            uselessReturns,
                            segment.allPrevSegments.filter(isReturned),
                            traversedSegments
                        );
                    }
                    continue;
                }

                uselessReturns.push(...segmentInfoMap.get(segment).uselessReturns);
            }

            return uselessReturns;
        }
function getUselessReturns(uselessReturns, prevSegments, providedTraversedSegments) {
            const traversedSegments = providedTraversedSegments || new WeakSet();

            for (const segment of prevSegments) {
                if (!segment.reachable) {
                    if (!traversedSegments.has(segment)) {
                        traversedSegments.add(segment);
                        getUselessReturns(
                            uselessReturns,
                            segment.allPrevSegments.filter(isReturned),
                            traversedSegments
                        );
                    }
                    continue;
                }

                uselessReturns.push(...segmentInfoMap.get(segment).uselessReturns);
            }

            return uselessReturns;
        }
function getUselessReturns ( uselessReturns , prevSegments , providedTraversedSegments ) { const traversedSegments = providedTraversedSegments || new WeakSet ( ) ; for ( const segment of prevSegments ) { if ( ! segment . reachable ) { if ( ! traversedSegments . has ( segment ) ) { traversedSegments . add ( segment ) ; getUselessReturns ( uselessReturns , segment . allPrevSegments . filter ( isReturned ) , traversedSegments ) ; } continue ; } uselessReturns . push ( ... segmentInfoMap . get ( segment ) . uselessReturns ) ; } return uselessReturns ; }
Collects useless return statements from the given previous segments.

A previous segment may be an unreachable segment.
In that case, the information object of the unreachable segment is not
initialized because `onCodePathSegmentStart` event is not notified for
unreachable segments.
This goes to the previous segments of the unreachable segment recursively
if the unreachable segment was generated by a return statement. Otherwise,
this ignores the unreachable segment.

This behavior would simulate code paths for the case that the return
statement does not exist.

@param {ASTNode[]} uselessReturns - The collected return statements.
@param {CodePathSegment[]} prevSegments - The previous segments to traverse.
@param {WeakSet<CodePathSegment>} [providedTraversedSegments] A set of segments that have already been traversed in this call
@returns {ASTNode[]} `uselessReturns`.
Collects useless return statements from the given previous segments .