Skip to content

refactor: remove unused require statements#21952

Merged
dduugg merged 1 commit intomainfrom
refactor/remove-unused-requires
Apr 8, 2026
Merged

refactor: remove unused require statements#21952
dduugg merged 1 commit intomainfrom
refactor/remove-unused-requires

Conversation

@dduugg
Copy link
Copy Markdown
Member

@dduugg dduugg commented Apr 8, 2026

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.

Where removing a top-level require exposed a missing direct dependency in a downstream file, the require was added there instead:

  • commands.rb now requires homebrew directly (uses Homebrew.require?)
  • diagnostic.rb now requires git_repository directly (uses GitRepository)
  • api/formula/formula_struct_generator.rb now requires deprecate_disable directly (uses DeprecateDisable)
  • system_config.rb now requires tap directly (uses CoreTap) and retains require "extend/ENV" (uses ENV.sensitive?, a method injected by that file)

All changes verified with brew lgtm --online.


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Claude Code was used to identify unused requires via static analysis (checking whether each required file's exported constants are referenced in the requiring file), verify each removal by reading the relevant files, and apply the changes. Each candidate was manually confirmed before editing. brew lgtm --online was run to verify style, types, and tests pass.

@dduugg dduugg force-pushed the refactor/remove-unused-requires branch from 7dbca08 to d1ff481 Compare April 8, 2026 18:30
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks, looks good when 🟢!

@dduugg dduugg force-pushed the refactor/remove-unused-requires branch 2 times, most recently from 6374679 to b267ada Compare April 8, 2026 18:47
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.
@dduugg dduugg force-pushed the refactor/remove-unused-requires branch from b267ada to de3512e Compare April 8, 2026 18:58
@dduugg dduugg marked this pull request as ready for review April 8, 2026 20:47
Copilot AI review requested due to automatic review settings April 8, 2026 20:47
@dduugg
Copy link
Copy Markdown
Member Author

dduugg commented Apr 8, 2026

Ok, let's try it, 🚢

@dduugg dduugg added this pull request to the merge queue Apr 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 require statements across many Homebrew modules/commands.
  • Replaced require "formula" with require "keg" in *-sync commands that only use Keg.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.

Merged via the queue into main with commit 1bfe9cf Apr 8, 2026
49 checks passed
@dduugg dduugg deleted the refactor/remove-unused-requires branch April 8, 2026 21:02
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.

3 participants