Skip to content

Remove redundant T.let annotations Sorbet can infer#23013

Merged
dduugg merged 1 commit into
mainfrom
redundant-t-let-autocorrect
Jul 8, 2026
Merged

Remove redundant T.let annotations Sorbet can infer#23013
dduugg merged 1 commit into
mainfrom
redundant-t-let-autocorrect

Conversation

@dduugg

@dduugg dduugg commented Jul 8, 2026

Copy link
Copy Markdown
Member

Remove T.let type annotations that Sorbet can infer on its own, applying the autocorrections from two new rubocop-sorbet cops:

  • Sorbet/RedundantTLet — constants assigned a constructor call (optionally .freeze'd), and initialize instance variables assigned directly from signature parameters.
  • Sorbet/RedundantTLetForLiteral — constants assigned simple literals and frozen literal arrays.

Eight annotations across seven files are removed:

  • bundle/extensions/uv.rb — regexp literal
  • dev-cmd/generate-zap.rb, extend/os/linux/{install,linkage_checker,sandbox}.rb, tap.rb — frozen literal arrays
  • install_steps.rb — a constructor-constant (X = Foo.new.freeze) and an initialize ivar

Why

These annotations are pure noise: Sorbet already infers the identical type, so they add maintenance cost (a type that must be kept in sync) without buying any checking. The constructor/frozen-literal cases depend on Sorbet's freeze-transparent inference (0.6.13304+); brew ships sorbet-static 0.6.13316, so the inference holds.

These two cops are new and not yet released — they come from the final version of Shopify/rubocop-sorbet#381 before it is opened for review. Landing their autocorrections here is a small, low-risk change that doubles as further public validation of the cops against a large real-world Sorbet codebase ahead of that PR's review.

brew typecheck passes with every annotation removed, confirming the inference is equivalent.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do?
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)?
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • AI was used to generate or assist with generating this PR.

AI (Claude Code) ran the two unreleased cops from a local checkout of the rubocop-sorbet branch against the brew source and applied their autocorrections. I reviewed the full diff, confirmed brew typecheck reports no errors and brew style passes on all changed files, and verified each removed annotation matches what Sorbet infers.

Apply the autocorrections from two new rubocop-sorbet cops,
Sorbet/RedundantTLet and Sorbet/RedundantTLetForLiteral, which flag
T.let annotations that Sorbet infers automatically:

- constants assigned a constructor call (optionally .freeze'd)
- constants assigned literals and frozen literal arrays
- initialize instance variables assigned from signature parameters

These rely on Sorbet's freeze-transparent inference (0.6.13304+); brew
ships sorbet-static 0.6.13316. `brew typecheck` passes with the
annotations removed.
Copilot AI review requested due to automatic review settings July 8, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes redundant Sorbet T.let annotations in typed: strict Ruby code where Sorbet can infer the same types automatically, reducing noise while preserving type safety across Homebrew’s core and Linux-specific code.

Changes:

  • Drop T.let(..., T::Array[String]) for frozen string-array constants in multiple files.
  • Drop T.let(..., Regexp) for a regexp constant in the uv bundle extension.
  • Drop redundant T.let for an initialize ivar assignment and a constructor-based constant.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Library/Homebrew/tap.rb Removes redundant T.let from a frozen %W[...] constant.
Library/Homebrew/install_steps.rb Removes redundant T.let from a TemplateVersion constant and an initialize ivar assignment.
Library/Homebrew/extend/os/linux/sandbox.rb Removes redundant T.let from a frozen string-array constant.
Library/Homebrew/extend/os/linux/linkage_checker.rb Removes redundant T.let from a frozen %W[...] allowlist constant.
Library/Homebrew/extend/os/linux/install.rb Removes redundant T.let from a frozen %W[...] runtime libs constant.
Library/Homebrew/dev-cmd/generate-zap.rb Removes redundant T.let from a frozen string-array constant.
Library/Homebrew/bundle/extensions/uv.rb Removes redundant T.let from a Regexp constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dduugg dduugg added this pull request to the merge queue Jul 8, 2026
Merged via the queue into main with commit 3d58a45 Jul 8, 2026
43 checks passed
@dduugg dduugg deleted the redundant-t-let-autocorrect branch July 8, 2026 18:27
@MikeMcQuaid

Copy link
Copy Markdown
Member

Nice, thanks!

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.

4 participants