Commit Graph
47 Commits
Author SHA1 Message Date
Mike McQuaid 204ea7e964 Make tests use public APIs and enable their cops
- 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.
2026-07-27 08:11:46 +01:00
Sam Ford 9c29e9694e Cask::Auditor: fix audit return type
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]`.
2026-06-07 17:23:40 -04:00
Douglas Eichelberger 6c237beceb sorbet: add strict type signatures to cask files
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
2026-04-10 13:08:44 -07:00
Mike McQuaid a1f112f3fe Move o* output methods to Utils::Output
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.
2025-08-20 19:20:19 +01:00
Mike McQuaidandEric Knibbe 55f65ec375 audit: ensure that official formula and cask names don't conflict.
Co-authored-by: Eric Knibbe <enk3@outlook.com>
2025-06-23 16:08:13 +01:00
Sam Ford c0f23acdcd Cask::Auditor: update language_blocks condition
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.
2025-04-23 09:19:41 -04:00
Douglas Eichelberger fcf18912fe Inline use of attr_predicate 2025-03-02 21:36:03 -08:00
Issy Long 45978435e7 rubocop: Use Sorbet/StrictSigil as it's better than comments
- 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
```
2024-08-12 15:24:27 +01:00
Markus Reiter 0f0055ede4 Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Mike McQuaid ea2892f8ee brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
Eric Knibbe e63b1f4da5 docs: monospace suggested values 2024-02-04 15:42:26 +01:00
Eric Knibbe 7698cf2098 audit: messaging improvements 2024-02-04 15:10:14 +01:00
Issy Long d636d2de37 Apply suggestions from review comments
- Rename `strictish` to `strict_only` in `add_error` method.
- Return just `errors`, a Set, not `{ errors: errors }`, a Hash,
  from `Auditor.audit`.
2023-04-06 00:10:28 +01:00
Issy Long e9f233e333 Remove unused output_warnings? Cask audit method 2023-04-01 02:02:23 +01:00
Issy Long 2b8127d518 Turn cask warnings into errors when --strict is passed (or implied)
- 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).
2023-04-01 01:56:46 +01:00
Issy Long a4e8f9e22b audit: Make --display-failures-only the default for Casks
- 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.
2023-04-01 01:56:45 +01:00
Markus Reiter bdd6523ce8 Deprecate appcast. 2023-03-30 03:29:06 +02:00
0589ac427d Update Library/Homebrew/cask/auditor.rb
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2023-02-28 23:00:43 +11:00
Bevan Kay d1b09a90da cask/auditor: only audit 10 languages by default on casks with many languages 2023-02-28 18:54:27 +11:00
Markus Reiter b821a00bc5 Pass only and except to cask audits. 2023-02-08 08:38:32 +01:00
Sean Molenaar ff54095b8a Cask: automatically add cask audits
This reverts commit 1661837465.
2022-09-13 11:19:33 +02:00
Mike McQuaidandGitHub 1661837465 Revert "Cask: automatically add cask audits" 2022-09-06 11:46:40 +01:00
Sean Molenaar 86f011cefb Cask: automatically add cask audits 2022-08-29 11:28:20 +02:00
Sean Molenaar e90371f8ab cask: add audit for incorrect signing 2022-08-11 09:11:29 +02:00
Rylan Polster b4a36bef64 audit: fix --display-failures-only failure messaging 2021-03-22 22:20:04 -04:00
Rylan Polster 2b8d19e0bd audit: limit non-failure cask output 2021-03-22 22:16:54 -04:00
Mike McQuaid d8a5e467e8 audit: quieten down and make casks audit consistent with formulae.
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.
2021-01-07 13:31:14 +00:00
Markus Reiter 24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Markus Reiter 5f005f67cf Refactor global Cask::Config. 2020-10-01 00:57:10 +02:00
Markus Reiter 16c17433d5 Fix passing options through Auditor. 2020-09-04 05:19:33 +02:00
Markus Reiter e5b56e485f Move cask audit implications into Audit. 2020-09-04 04:47:31 +02:00
Markus Reiter 55206bdc56 Document Auditor. 2020-08-26 03:13:59 +02:00
Markus Reiter b48bc316e0 Use CLI::Parser for cask commands. 2020-08-13 05:15:15 +02:00
Markus Reiter 8a32954940 Move cask/all to just cask. 2020-08-09 01:34:07 +02:00
Markus Reiter 5cf7ffd93e Make Cask::Auditor return a Hash with warnings and errors. 2020-07-28 09:50:15 +02:00
Markus Reiter 8d148b1fbc Remove special-casing of MacOS::languages. 2020-07-22 01:09:14 +02:00
Markus Reiter ee09df8db3 Move Download from Auditor into Audit. 2020-07-22 01:09:14 +02:00
Sean Molenaar 3567892802 Add notibility checks for casks 2020-05-26 14:21:25 +02:00
Mike McQuaid ef95b59ed4 Remove HomebrewArgvExtension
Fixes #5730
2020-05-23 19:39:11 +01:00
Julian Mayer a061a8d9f7 add optional checking whether appcast contains the version stanza to "brew cask audit" 2019-05-07 17:06:54 +02:00
Mike McQuaid 36dbad3922 Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
Markus Reiter e472c35880 Remove unneeded cleanup. 2019-01-13 20:29:52 +01:00
Markus Reiter 3435202f91 Fix missing require. 2019-01-13 20:26:46 +01:00
Mike McQuaid 737b84b54b brew style --fix fixes. 2018-11-02 17:29:23 +00:00
Markus Reiter 16618d0fc7 Use ActiveSupport’s #pluralize and #to_sentence. 2018-10-07 23:10:56 +02:00
Markus Reiter a84a1c63db Rename Hbc module to Cask. 2018-09-06 09:30:52 +02:00
Mike McQuaid 90b3a13909 cask: move cask/lib/hbc/* to cask/*.
Fix the load path, requires and some filenames accordingly.
2018-09-04 09:56:57 +01:00