Skip to content

Enable Sorbet/ConstantsFromStrings and override cops#22758

Open
MikeMcQuaid wants to merge 1 commit into
mainfrom
enable-sorbet-constants-cops
Open

Enable Sorbet/ConstantsFromStrings and override cops#22758
MikeMcQuaid wants to merge 1 commit into
mainfrom
enable-sorbet-constants-cops

Conversation

@MikeMcQuaid

Copy link
Copy Markdown
Member
  • drop the blanket Sorbet/ConstantsFromStrings disable and the directory-wide Sorbet/AllowIncompatibleOverride exclude so both cops run across the codebase again
  • convert the brew bundle PACKAGE_TYPE, PACKAGE_TYPE_NAME and BANNER_NAME constants into abstract type, check_label and banner_name methods so the base classes no longer reach into subclass constants via const_get
  • replace the brew.rb and system_config.rb const_get lookups with direct constant references
  • annotate the remaining genuinely dynamic const_get lookups with scoped rubocop:disable blocks explaining why they must stay

  • 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? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • 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 Opus 4.8 high with local review and testing.


- drop the blanket `Sorbet/ConstantsFromStrings` disable and the
  directory-wide `Sorbet/AllowIncompatibleOverride` exclude so both
  cops run across the codebase again
- convert the `brew bundle` `PACKAGE_TYPE`, `PACKAGE_TYPE_NAME` and
  `BANNER_NAME` constants into abstract `type`, `check_label` and
  `banner_name` methods so the base classes no longer reach into
  subclass constants via `const_get`
- replace the `brew.rb` and `system_config.rb` `const_get` lookups
  with direct constant references
- annotate the remaining genuinely dynamic `const_get` lookups with
  scoped `rubocop:disable` blocks explaining why they must stay
Copilot AI review requested due to automatic review settings June 16, 2026 08:31

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

This PR re-enables Sorbet/ConstantsFromStrings and Sorbet/AllowIncompatibleOverride across the Homebrew codebase by removing broad RuboCop disables/excludes, replacing avoidable reflective constant lookups with direct references or abstract class methods, and scoping the remaining genuinely-dynamic constant access behind localized RuboCop disable blocks with justification.

Changes:

  • Remove blanket/dir-wide RuboCop configuration exceptions for the Sorbet cops and replace them with targeted rubocop:disable blocks where reflection is required.
  • Refactor brew bundle package-type metadata from subclass constants into abstract class methods (type, check_label, banner_name) to avoid const_get on subclass constants.
  • Replace a few const_get usages with direct constant references in brew.rb and system_config.rb.

Reviewed changes

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

Show a summary per file
File Description
Library/Homebrew/utils/fork.rb Adds a scoped RuboCop disable around deserializing an exception class name via Object.const_get.
Library/Homebrew/unpack_strategy.rb Adds a scoped RuboCop disable around dynamic strategy class resolution via const_get.
Library/Homebrew/test/unpack_strategy/dmg_spec.rb Adds a scoped RuboCop disable for accessing a private strategy constant in a test.
Library/Homebrew/test/support/helper/cmd/brew-verify-undefined.rb Adds a scoped RuboCop disable for iterating over a list of constant names with Object.const_get.
Library/Homebrew/test/sandbox_shared_spec.rb Adds a scoped RuboCop disable for dynamically selecting which constant to operate on in examples.
Library/Homebrew/test/requirement_spec.rb Adds a scoped RuboCop disable for resolving a stubbed class by name at runtime.
Library/Homebrew/test/exceptions_spec.rb Adds scoped RuboCop disables around reflective constant access on a dynamically-built test module.
Library/Homebrew/test/cmd/shared_examples/args_parse.rb Adds a scoped RuboCop disable where the command class is only known at runtime.
Library/Homebrew/test/cmd/bundle/check_subcommand_spec.rb Updates the test checker stub to implement new abstract metadata methods instead of defining constants.
Library/Homebrew/system_config.rb Replaces reflective access to HOMEBREW_REPOSITORY/HOMEBREW_CELLAR with direct constant references.
Library/Homebrew/sorbet/tapioca/compilers/api_structs.rb Adds a scoped RuboCop disable for runtime-resolved struct predicate generation via const_get.
Library/Homebrew/prof/vernier_fork_guard.rb Adds scoped RuboCop disables for dynamic lookup of Vernier::Autorun (not present in the RBI).
Library/Homebrew/livecheck/strategy/extract_plist.rb Adds a scoped RuboCop disable around an intentionally incompatible Sorbet override signature.
Library/Homebrew/livecheck/strategy.rb Adds scoped RuboCop disables for dynamic strategy discovery and optional PRIORITY constant access.
Library/Homebrew/formulary.rb Adds a scoped RuboCop disable around runtime formula class/module resolution via const_get.
Library/Homebrew/formula.rb Adds a scoped RuboCop disable for runtime namespace/constant lookup of formula build flags.
Library/Homebrew/cask/artifact/abstract_flight_block.rb Adds a scoped RuboCop disable for dynamically-derived DSL class resolution.
Library/Homebrew/bundle/tap.rb Implements type/check_label methods on the Tap package type (replacing constants).
Library/Homebrew/bundle/package_type.rb Replaces subclass-constant reflection with abstract metadata methods and updates call sites accordingly.
Library/Homebrew/bundle/extensions/winget.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/vscode_extension.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/uv.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/npm.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/mac_app_store.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/krew.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/go.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/flatpak.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/extensions/extension.rb Removes constant-based metadata methods and makes banner_name abstract (with metadata coming from abstract methods).
Library/Homebrew/bundle/extensions/cargo.rb Implements type/check_label/banner_name methods (replacing constants).
Library/Homebrew/bundle/cask.rb Implements type/check_label methods on the Cask package type (replacing constants).
Library/Homebrew/bundle/brew.rb Implements type/check_label methods on the Brew package type (replacing constants).
Library/Homebrew/brew.rb Replaces reflective constant access used to set env vars with direct constant references.
Library/.rubocop.yml Removes the global/dir-wide exceptions so the Sorbet cops run across the codebase again.

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

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.

2 participants