- Make every statically-poked method public and call it directly,
keeping `public_send` only for dynamically-named public methods.
- Read and write state through public `attr_*` accessors instead of
instance variable reflection.
- Enable `Homebrew/NoSendInTests` and
`Homebrew/NoInstanceVariableAccessInTests` now the test suite is
clean, so neither pattern creeps back in.
- Keep rare justified disables, e.g. `Module#remove_const` is
private core Ruby and raw memoisation state has no accessor.
When the `HOMEBREW_SORBET_RECURSIVE=1` environment variable is set,
running `brew audit` on a cask with audit errors will produce a type
error: `Return value: Expected type T::Set[String], got
T::Set[T::Hash[Symbol, T.nilable(T.any(String, T::Boolean))]]`. This
occurs because the `Cask::Auditor.audit` and `#audit` methods are
expected to return a Set of strings but the Set is populated with
`Cask::Audit::Error` objects, which is a type alias for a specific
hash structure. This updates the related return types to use
`T::Set[Audit::Error]`.
Add Sorbet `sig` annotations to the cask-related files that were
already marked `# typed: strict` but lacked complete signatures.
Key changes:
- Add `sig` and `T.let` declarations to cask/cask.rb, cask/dsl.rb,
cask/cask_loader.rb, cask/installer.rb, cask/exceptions.rb,
cask/quarantine.rb, and cask/dsl/caveats.rb
- Use `T::Sig::WithoutRuntime.sig` for `DSL#url`, `DSL#set_unique_stanza`,
and `CaskLoader.{path,load,for}` to avoid Sorbet runtime wrappers
interfering with `caller_locations` (used by `URL#unversioned?`) and
RSpec mocking of class methods
- Fix nil guards using raise-unless patterns instead of `T.must`
- Avoid `T.unsafe`; use `T.untyped` only as hash value types
- Fix cascade type errors in callers (audit.rb, info.rb, upgrade.rb,
livecheck, bump-cask-pr.rb, etc.) that now see explicit nilable types
on `Cask#tap`, `CaskLoader.load`, and related methods
This reduces the surface area of our `Kernel` monkeypatch and removes
the need to `include Kernel` in a bunch of modules.
While we're here, also move `Kernel#require?` to `Homebrew` and fully
scope the calls to it.
I recently modified `Cask::DSL` to define instance variables in the
`#initialize` method and this involved some changes to the `language`,
`language_eval`, and `languages` methods. One of those was to
initialize `@language_blocks` to an empty hash instead of using a
`nil` default. I updated the related condition in the `language_eval`
method but I missed that `language_blocks` is used in `Cask::Auditor`
and it specifically relies on a false-y value to check if the variable
is set. An empty hash isn't false-y, so this is causing issues for
`brew audit`.
This updates the condition in `Cask::Auditor` to check for a non-empty
hash instead, which resolves the issue.
- Previously I thought that comments were fine to discourage people from
wasting their time trying to bump things that used `undef` that Sorbet
didn't support. But RuboCop is better at this since it'll complain if
the comments are unnecessary.
- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.
- I've gone for a mixture of `rubocop:disable` for the files that can't
be `typed: strict` (use of undef, required before everything else, etc)
and `rubocop:todo` for everything else that should be tried to make
strictly typed. There's no functional difference between the two as
`rubocop:todo` is `rubocop:disable` with a different name.
- And I entirely disabled the cop for the docs/ directory since
`typed: strict` isn't going to gain us anything for some Markdown
linting config files.
- This means that now it's easier to track what needs to be done rather
than relying on checklists of files in our big Sorbet issue:
```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
268
```
- And this is confirmed working for new files:
```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
(use "git add <file>..." to include in what will be committed)
Library/Homebrew/bad.rb
Library/Homebrew/good.rb
nothing added to commit but untracked files present (use "git add" to track)
$ brew style
Offenses:
bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^
1340 files inspected, 1 offense detected
```
- Ignore them and don't show them otherwise.
- Part three of issue 15074:
> As a result, I propose that all current cask audit warnings are never
> displayed as warnings but the underlying audit checks turned into
> errors displayed only with --strict (or one of the other relevant
> flags).
- Cask warnings are really noisy and numerous. Let's only show them if
the user passes `--strict` or something implying `--strict`, like
`--new-cask`.
- Additionally remove `display_passes` since we would like silence if
nothing is wrong with the cask, the same as with formula audits.
The current casks audit is very noisy in the no-op case (i.e. no errors)
https://github.com/Homebrew/brew/pull/10234/checks?check_run_id=1655630568#step:15:7
This means when there are errors and you're querying all casks it's
pretty hard to quickly identify the problems.
This commit silences the `passing`, `warning` and header/summary output
when you're querying all casks (rather than a specific cask or tap).
This is more consistent with `brew audit` for formulae which is silent
unless there are audit failures.