Skip to content

outbox-listener-delivery-required counts delivery inside while (false) #1053

Description

@dahlia

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions