Skip to content

test: derive enum members and mocked interfaces as live - #7321

Merged
otavio merged 1 commit into
masterfrom
test/deadcode-type-liveness
Oct 5, 2026
Merged

otavio merged 1 commit into
masterfrom
test/deadcode-type-liveness

Conversation

@otavio

@otavio otavio commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Summary

The dead-code check counted a declaration as used only where code named it. Two kinds of declarations that must stay had to be listed by hand in .deadcode-allow, and a listed one failed the check again once a test named it: cloud#2616 hit that with SubscriptionStatusCanceled. Both kinds are now derived from the types, and both allowlists go.

 live(declaration)
   named anywhere outside mocks
+  or an enum member (constant of a named type from its own package) whose
+     type is used beyond its members' declarations, or a sibling member is used
+  or an interface with methods that a type in a mocks/ package implements
Former entry Now live because
cloud: SubscriptionStatus{Canceled,Incomplete,IncompleteExpired,Unpaid,Paused} SubscriptionStatus is used as a type
cloud: InvoiceStatusUncollectible its siblings InvoiceStatusOpen/Draft/Paid are used
cloud: Backend stripe/mocks.MockBackend implements it
shellhub: KindInvalid Kind is used as a type

An enum whose type and members nobody uses is still reported, and so is an interface nothing mocks. The allowlist mechanism stays for a real exception.

Evidence

  • Before: TestUnusedDeclarations (a fixture module with a used-type enum, a used-sibling enum, an unused enum, a mocked interface and an unmocked one) reports all of them.
    After: it reports only the unused enum's members and the unmocked interface.
  • Full run over shellhub and cloud (go run ./cmd/deadcode -require-cloud):
    • with the allowlists in place, every entry is reported as "used now, or gone; drop the entry"
    • with both allowlists deleted, it prints no dead code

Merge Danger

Door: two-way

Blast Radius: dead-code check

Paired with shellhub-io/cloud#2617 on the same branch name, which deletes cloud's allowlist. Merge the two back to back: either one alone makes the scheduled sweep of both masters report the other repository's allowlist (stale entries under the new check, or dead symbols under the old one).

shellhub-io/cloud#2616 removes one line from cloud's .deadcode-allow. Whichever of the two merges second needs a rebase.

…ode check

The check counted a declaration as used only where code named it, so two kinds of declarations
that must stay had to be listed by hand in .deadcode-allow, and the list failed again the moment a
test started naming one. Both kinds can be read off the types instead.

An exported constant of a named type from its own package is an enum member. Its values often
arrive by conversion, as Stripe's statuses do through SubscriptionStatus(sub.Status), so no code
names the member that matches. It is now live while its type is used anywhere other than its own
members' declarations, or while any sibling member is used: InvoiceStatus is never used as a type,
only through string(InvoiceStatusOpen), and its uncollectible member is no less real for that.
An enum whose type and members nobody uses is still reported.

An interface that a type in a mocks/ package implements is mockery's input, and the generated mock
never names it. It is now live, checked with types.Implements against every type the mocks declare,
so .mockery.yaml is not read. An interface without methods is left out, since every mock would
implement it.

With both rules nothing in shellhub or cloud needs an entry, so shellhub's .deadcode-allow goes;
cloud drops its own on the branch of the same name. The allowlist stays for a real exception.
@otavio
otavio requested a review from a team as a code owner October 3, 2026 23:11
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Code Review Complete

The automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, comment /review.

View job

@otavio
otavio merged commit e873c45 into master Oct 5, 2026
32 checks passed
@otavio
otavio deleted the test/deadcode-type-liveness branch October 5, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant