Why
outbox-listener-delivery-required (@fedify/lint) skips a delivery call behind if (false) but counts one inside while (false). The two are equally dead, and isStaticallyFalsy(), the helper that decides the first case, already sits in the same file.
federation
.setOutboxListeners("/users/{identifier}/outbox")
.on(Activity, async (ctx, activity) => {
while (false) {
await ctx.sendActivity({ identifier: ctx.identifier }, inbox, activity);
}
console.log(ctx.identifier, activity.id?.href);
});
This listener never federates the posted activity, and the rule says nothing. It is a missed detection rather than a false report, so no valid code breaks today. The behavior predates the reachability rewrite in #1050 and is the same in every released version of the rule.
Scope
In collectReachableStatements(), skip the body of a WhileStatement or a ForStatement whose test is statically falsy. A ForStatement with no test loops forever, so prune only when a test is present and falsy.
Leave do…while alone. Its body runs once before the test is evaluated, so a delivery call there really does happen; while (false) and do…while (false) are not interchangeable. CodeRabbit raised the same caveat while reviewing #1050.
Non-goals
No constant folding beyond what is already there. isStaticallyFalsy() recognizes a literal and nothing else, and widening it to evaluate expressions belongs in a separate discussion.
Suggested checks
Add cases to packages/lint/src/tests/outbox-listener-delivery-required.test.ts covering while (false), for (; false;), and a do…while (false) whose body delivers. The last one must keep passing.
Why
outbox-listener-delivery-required(@fedify/lint) skips a delivery call behindif (false)but counts one insidewhile (false). The two are equally dead, andisStaticallyFalsy(), the helper that decides the first case, already sits in the same file.This listener never federates the posted activity, and the rule says nothing. It is a missed detection rather than a false report, so no valid code breaks today. The behavior predates the reachability rewrite in #1050 and is the same in every released version of the rule.
Scope
In
collectReachableStatements(), skip the body of aWhileStatementor aForStatementwhose test is statically falsy. AForStatementwith no test loops forever, so prune only when a test is present and falsy.Leave
do…whilealone. Its body runs once before the test is evaluated, so a delivery call there really does happen;while (false)anddo…while (false)are not interchangeable. CodeRabbit raised the same caveat while reviewing #1050.Non-goals
No constant folding beyond what is already there.
isStaticallyFalsy()recognizes a literal and nothing else, and widening it to evaluate expressions belongs in a separate discussion.Suggested checks
Add cases to packages/lint/src/tests/outbox-listener-delivery-required.test.ts covering
while (false),for (; false;), and ado…while (false)whose body delivers. The last one must keep passing.