refactor: remove unused require statements#21952
Merged
Conversation
7dbca08 to
d1ff481
Compare
MikeMcQuaid
approved these changes
Apr 8, 2026
Member
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks, looks good when 🟢!
6374679 to
b267ada
Compare
Remove 29 unnecessary `require` statements across 30 files where the required file's exported constants are never referenced in the requiring file. Three env-sync commands (`nodenv-sync`, `pyenv-sync`, `rbenv-sync`) had `require "formula"` despite only using `Keg.new` — replaced with `require "keg"` to match actual usage. `commands.rb` previously relied on a transitive load chain (`require "utils"` → `require "homebrew"`) for `Homebrew.require?`. That dependency is now explicit. `diagnostic.rb` was using `GitRepository` via a transitive load through `system_config.rb`. Now requires `git_repository` directly.
b267ada to
de3512e
Compare
Member
Author
|
Ok, let's try it, 🚢 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces unnecessary Ruby load-time dependencies by removing require statements for files whose exported constants aren’t referenced, and tightening a few requires to match actual usage.
Changes:
- Removed unused
requirestatements across many Homebrew modules/commands. - Replaced
require "formula"withrequire "keg"in*-synccommands that only useKeg.new. - Added a small number of direct
requires where removing an upstream require revealed a missing direct dependency (e.g.,tap,git_repository,deprecate_disable,homebrew).
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Library/Homebrew/utils/tty.rb | Removes unused utils/output require from TTY helper module. |
| Library/Homebrew/utils.rb | Removes unused homebrew require from general-purpose utility module. |
| Library/Homebrew/system_config.rb | Replaces software_spec require with tap to match CoreTap usage. |
| Library/Homebrew/sbom.rb | Removes unused cxxstdlib and cachable requires from SBOM generation. |
| Library/Homebrew/rubocops/lines.rb | Removes unused macos_version require from RuboCop cop implementation. |
| Library/Homebrew/formulary.rb | Removes unused deprecate_disable require from formulary loader code. |
| Library/Homebrew/download_strategy.rb | Removes unused lazy_object require from download strategy base. |
| Library/Homebrew/diagnostic.rb | Removes unused requires and adds git_repository for direct GitRepository usage. |
| Library/Homebrew/dev-cmd/audit.rb | Removes unused formula_versions and utils/shared_audits requires. |
| Library/Homebrew/descriptions.rb | Removes unused formula_versions require. |
| Library/Homebrew/commands.rb | Switches from require "utils" to require "homebrew" for Homebrew.require?. |
| Library/Homebrew/cmd/upgrade.rb | Removes unused cask/macos require. |
| Library/Homebrew/cmd/search.rb | Removes unused descriptions require. |
| Library/Homebrew/cmd/reinstall.rb | Removes unused cask/macos require. |
| Library/Homebrew/cmd/rbenv-sync.rb | Replaces require "formula" with require "keg" to match Keg usage. |
| Library/Homebrew/cmd/pyenv-sync.rb | Replaces require "formula" with require "keg" to match Keg usage. |
| Library/Homebrew/cmd/postinstall.rb | Removes unused sandbox require. |
| Library/Homebrew/cmd/outdated.rb | Removes unused keg require. |
| Library/Homebrew/cmd/nodenv-sync.rb | Replaces require "formula" with require "keg" to match Keg usage. |
| Library/Homebrew/cmd/missing.rb | Removes unused tab require. |
| Library/Homebrew/cmd/info.rb | Removes unused keg require. |
| Library/Homebrew/caveats.rb | Removes unused language/python require. |
| Library/Homebrew/cask/url.rb | Removes unused utils/curl require. |
| Library/Homebrew/cask/dsl/base.rb | Removes unused on_system require from base DSL stanza class. |
| Library/Homebrew/cask/dsl.rb | Removes unused lazy_object require. |
| Library/Homebrew/cask/cask.rb | Removes unused utils/bottles require. |
| Library/Homebrew/cask/audit.rb | Removes unused utils/git require. |
| Library/Homebrew/bundle/skipper.rb | Removes unused hardware require. |
| Library/Homebrew/brew.rb | Removes unused warnings require from brew entrypoint. |
| Library/Homebrew/api/formula/formula_struct_generator.rb | Adds direct deprecate_disable require for DeprecateDisable usage. |
| Library/Homebrew/api/formula.rb | Removes unused autobump_constants require. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remove 29 unnecessary
requirestatements across 30 files where the required file's exported constants are never referenced in the requiring file.Three env-sync commands (
nodenv-sync,pyenv-sync,rbenv-sync) hadrequire "formula"despite only usingKeg.new— replaced withrequire "keg"to match actual usage.Where removing a top-level require exposed a missing direct dependency in a downstream file, the require was added there instead:
commands.rbnow requireshomebrewdirectly (usesHomebrew.require?)diagnostic.rbnow requiresgit_repositorydirectly (usesGitRepository)api/formula/formula_struct_generator.rbnow requiresdeprecate_disabledirectly (usesDeprecateDisable)system_config.rbnow requirestapdirectly (usesCoreTap) and retainsrequire "extend/ENV"(usesENV.sensitive?, a method injected by that file)All changes verified with
brew lgtm --online.brew lgtm(style, typechecking and tests) with your changes locally?brew lgtm --onlinewas run to verify style, types, and tests pass.