lib/rules/no-useless-return.js
function markReturnStatementsOnSegmentAsUsed(segment) {
            if (!segment.reachable) {
                usedUnreachableSegments.add(segment);
                segment.allPrevSegments
                    .filter(isReturned)
                    .filter(prevSegment => !usedUnreachableSegments.has(prevSegment))
                    .forEach(markReturnStatementsOnSegmentAsUsed);
                return;
            }

            const info = segmentInfoMap.get(segment);

            for (const node of info.uselessReturns) {
                remove(scopeInfo.uselessReturns, node);
            }
            info.uselessReturns = [];
        }
function markReturnStatementsOnSegmentAsUsed(segment) {
            if (!segment.reachable) {
                usedUnreachableSegments.add(segment);
                segment.allPrevSegments
                    .filter(isReturned)
                    .filter(prevSegment => !usedUnreachableSegments.has(prevSegment))
                    .forEach(markReturnStatementsOnSegmentAsUsed);
                return;
            }

            const info = segmentInfoMap.get(segment);

            for (const node of info.uselessReturns) {
                remove(scopeInfo.uselessReturns, node);
            }
            info.uselessReturns = [];
        }
function markReturnStatementsOnSegmentAsUsed ( segment ) { if ( ! segment . reachable ) { usedUnreachableSegments . add ( segment ) ; segment . allPrevSegments . filter ( isReturned ) . filter ( prevSegment => ! usedUnreachableSegments . has ( prevSegment ) ) . forEach ( markReturnStatementsOnSegmentAsUsed ) ; return ; } const info = segmentInfoMap . get ( segment ) ; for ( const node of info . uselessReturns ) { remove ( scopeInfo . uselessReturns , node ) ; } info . uselessReturns = [ ] ; }
Removes the return statements on the given segment from the useless return
statement list.

This 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 {CodePathSegment} segment - The segment to get return statements.
@returns {void}
Removes the return statements on the given segment from the useless return statement list .