Enable Sorbet/ConstantsFromStrings and override cops#22758
Open
MikeMcQuaid wants to merge 1 commit into
Open
Conversation
- 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
Contributor
There was a problem hiding this comment.
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:disableblocks where reflection is required. - Refactor
brew bundlepackage-type metadata from subclass constants into abstract class methods (type,check_label,banner_name) to avoidconst_geton subclass constants. - Replace a few
const_getusages with direct constant references inbrew.rbandsystem_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.
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.
Sorbet/ConstantsFromStringsdisable and the directory-wideSorbet/AllowIncompatibleOverrideexclude so both cops run across the codebase againbrew bundlePACKAGE_TYPE,PACKAGE_TYPE_NAMEandBANNER_NAMEconstants into abstracttype,check_labelandbanner_namemethods so the base classes no longer reach into subclass constants viaconst_getbrew.rbandsystem_config.rbconst_getlookups with direct constant referencesconst_getlookups with scopedrubocop:disableblocks explaining why they must staybrew lgtm(style, typechecking and tests) with your changes locally?Claude Opus 4.8 high with local review and testing.