audit: add --fix command for casks - #23618
Conversation
There was a problem hiding this comment.
Pull request overview
Adds brew audit --fix support for casks to automatically correct a small set of common audit failures (to reduce maintainer workload and improve brew bump flows), and updates user-facing docs/completions accordingly.
Changes:
- Extend
brew audit --fixso cask audits can auto-correct:depends_on macos:minimums, artifact stanza case mismatches, and deprecatedurl ... verified:usage. - Add AST helpers + specs to support the cask rewrites, and extend cask audit specs to validate “corrected” behavior and rollback on invalid rewrites.
- Make
bump-cask-prrun cask audit with--fixand add documentation/manpage/completions text describing the expanded behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| manpages/brew.1 | Documents audit --fix behavior for casks in the generated manpage. |
| Library/Homebrew/utils/ast.rb | Adds CaskAST rewrite helpers for removing hash pairs and updating/inserting depends_on macos: stanzas. |
| Library/Homebrew/test/utils/ast/cask_ast_spec.rb | Adds unit specs for the new CaskAST rewrite helpers. |
| Library/Homebrew/test/cask/audit_spec.rb | Adds coverage for cask audit auto-fixes + rollback behavior. |
| Library/Homebrew/dev-cmd/bump-cask-pr.rb | Runs cask audit with --fix and adds a dedicated min_os fix pass for autobump bot flows. |
| Library/Homebrew/dev-cmd/audit.rb | Adds audit_fix plumbing, treats “all problems corrected” as success, and suppresses corrected issues in GHA annotations. |
| Library/Homebrew/cask/auditor.rb | Plumbs the audit_fix option through to Cask::Audit. |
| Library/Homebrew/cask/audit.rb | Implements fix-capable paths for verified, artifact case, and min_os audits, and marks corrected problems. |
| docs/Manpage.md | Updates the manpage documentation source for audit --fix. |
| completions/zsh/_brew | Updates audit --fix completion help text. |
| completions/fish/brew.fish | Updates audit --fix completion help text. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| # e.g. `url "...", verified: "..."` becomes `url "..."`. | ||
| preceding = stanza_node.arguments.find { |argument| !argument.hash_type? } | ||
| next if preceding.nil? | ||
|
|
||
| pair.source_range.with(begin_pos: preceding.source_range.end_pos) |
| ohai "Skipping `brew audit`" | ||
| else | ||
| ohai "brew audit --cask --online #{cask.full_name}" | ||
| ohai "brew audit --cask --online --fix #{cask.full_name}" |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
IMO particularly if we're using ASTs: I think it makes more sense to move these checks into RuboCops to be fixed with brew style --fix rather than adding brew audit --fix. Most audits can't be fixed automatically. Thoughts?
|
I did think about this, and is part of the reason I opened this tentatively as a draft for now, to discuss implementation. As far as I can see, nothing in the Rubocop side runs any "package-level" checks, so there's no integration with archive extraction etc.. This is required to resolve the issues that are being fixed here. The alternative option to consider would be Rubocop checks that sit behind a separate flag, but at the moment there's not "style" checks that require network access at all, so it would double up on extraction and work that is being complete in -- Just one clarification, the |
This PR introduces a
--fixflag for brew audit, with the goal being to correct some common cask audit failures, to use withbrew bump. This will reduce maintainer workload, and could be extended to additional corrections that occur regularly.Automatic corrections can be applied for issues with;
depends_on macos:verifiedparameter automatically removed from urls.Corrected problems are reported as corrected rather than failing the audit (matching brew style --fix), and are excluded from GitHub Actions annotations. If a rewrite produces a cask that no longer loads, the original file is restored.
Note:
brew bump-cask-prpasses--fixby default. Sobrew bumpwill automatically fix these issues. This matches the existing behaviour of thebrew stylechecks within this process.brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?I used
claude-codewith Opus 5 to create the changes.