diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4d78251af0..6bd11465a0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -77,7 +77,7 @@ jobs: run: brew style --display-cop-names homebrew/core - name: Run brew audit --skip-style on all taps - run: brew audit --skip-style + run: brew audit --skip-style --display-failures-only - name: Set up all Homebrew taps run: | @@ -277,10 +277,10 @@ jobs: - name: Run brew audit --skip-style on Cask taps run: | - brew audit --skip-style --tap=homebrew/cask - brew audit --skip-style --tap=homebrew/cask-drivers - brew audit --skip-style --tap=homebrew/cask-fonts - brew audit --skip-style --tap=homebrew/cask-versions + brew audit --skip-style --display-failures-only --tap=homebrew/cask + brew audit --skip-style --display-failures-only --tap=homebrew/cask-drivers + brew audit --skip-style --display-failures-only --tap=homebrew/cask-fonts + brew audit --skip-style --display-failures-only --tap=homebrew/cask-versions - name: Install brew tests dependencies run: | diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 2ec90d9915..a3255b2cea 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -126,8 +126,10 @@ module Cask end end - sig { returns(String) } - def summary + sig { params(include_passed: T::Boolean).returns(String) } + def summary(include_passed: false) + return if success? && !include_passed + summary = ["audit for #{cask}: #{result}"] errors.each do |error| diff --git a/Library/Homebrew/cask/auditor.rb b/Library/Homebrew/cask/auditor.rb index dd86237016..178ee3e4b2 100644 --- a/Library/Homebrew/cask/auditor.rb +++ b/Library/Homebrew/cask/auditor.rb @@ -18,7 +18,9 @@ module Cask audit_token_conflicts: nil, quarantine: nil, any_named_args: nil, - language: nil + language: nil, + display_passes: nil, + display_failures_only: nil ) new( cask, @@ -31,6 +33,8 @@ module Cask quarantine: quarantine, any_named_args: any_named_args, language: language, + display_passes: display_passes, + display_failures_only: display_failures_only, ).audit end @@ -46,7 +50,9 @@ module Cask audit_new_cask: nil, quarantine: nil, any_named_args: nil, - language: nil + language: nil, + display_passes: nil, + display_failures_only: nil ) @cask = cask @audit_download = audit_download @@ -58,6 +64,8 @@ module Cask @audit_token_conflicts = audit_token_conflicts @any_named_args = any_named_args @language = language + @display_passes = display_passes + @display_failures_only = display_failures_only end def audit @@ -67,13 +75,18 @@ module Cask if !language && language_blocks language_blocks.each_key do |l| audit = audit_languages(l) - puts audit.summary if output_summary?(audit) + summary = audit.summary(include_passed: output_passed?) + if summary.present? && output_summary?(audit) + ohai "Auditing language: #{l.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary? + puts summary + end warnings += audit.warnings errors += audit.errors end else audit = audit_cask_instance(cask) - puts audit.summary if output_summary?(audit) + summary = audit.summary(include_passed: output_passed?) + puts summary if summary.present? && output_summary?(audit) warnings += audit.warnings errors += audit.errors end @@ -84,6 +97,7 @@ module Cask private def output_summary?(audit = nil) + return false if @display_failures_only.present? return true if @any_named_args.present? return true if @audit_strict.present? return false if audit.blank? @@ -91,9 +105,14 @@ module Cask audit.errors? end - def audit_languages(languages) - ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary? + def output_passed? + return false if @display_failures_only.present? + return true if @display_passes.present? + false + end + + def audit_languages(languages) original_config = cask.config localized_config = original_config.merge(Config.new(explicit: { languages: languages })) cask.config = localized_config diff --git a/Library/Homebrew/cask/cmd/audit.rb b/Library/Homebrew/cask/cmd/audit.rb index 2afdd73428..d49e396df9 100644 --- a/Library/Homebrew/cask/cmd/audit.rb +++ b/Library/Homebrew/cask/cmd/audit.rb @@ -27,6 +27,8 @@ module Cask description: "Run various additional style checks to determine if a new cask is eligible " \ "for Homebrew. This should be used when creating new casks and implies " \ "`--strict` and `--online`" + switch "--display-failures-only", + description: "Only display casks that fail the audit. This is the default for formulae." end end @@ -44,15 +46,17 @@ module Cask results = self.class.audit_casks( *casks, - download: args.download?, - appcast: args.appcast?, - online: args.online?, - strict: args.strict?, - new_cask: args.new_cask?, - token_conflicts: args.token_conflicts?, - quarantine: args.quarantine?, - any_named_args: any_named_args, - language: args.language, + download: args.download?, + appcast: args.appcast?, + online: args.online?, + strict: args.strict?, + new_cask: args.new_cask?, + token_conflicts: args.token_conflicts?, + quarantine: args.quarantine?, + any_named_args: any_named_args, + language: args.language, + display_passes: args.verbose? || args.named.count == 1, + display_failures_only: args.display_failures_only?, ) self.class.print_annotations(results) @@ -73,7 +77,9 @@ module Cask token_conflicts: nil, quarantine: nil, any_named_args: nil, - language: nil + language: nil, + display_passes: nil, + display_failures_only: nil ) options = { audit_download: download, @@ -85,6 +91,8 @@ module Cask quarantine: quarantine, language: language, any_named_args: any_named_args, + display_passes: display_passes, + display_failures_only: display_failures_only, }.compact options[:quarantine] = true if options[:quarantine].nil? diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 91c56b000f..2076a617b0 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -56,6 +56,8 @@ module Homebrew switch "--display-filename", description: "Prefix every line of output with the file or formula name being audited, to "\ "make output easy to grep." + switch "--display-failures-only", + description: "Only display casks that fail the audit. This is the default for formulae." switch "--skip-style", description: "Skip running non-RuboCop style checks. Useful if you plan on running "\ "`brew style` separately. Enabled by default unless a formula is specified by name." @@ -213,15 +215,17 @@ module Homebrew Cask::Cmd::Audit.audit_casks( *audit_casks, - download: nil, - appcast: args.appcast?, - online: args.online?, - strict: args.strict?, - new_cask: args.new_cask?, - token_conflicts: args.token_conflicts?, - quarantine: nil, - any_named_args: !no_named_args, - language: nil, + download: nil, + appcast: args.appcast?, + online: args.online?, + strict: args.strict?, + new_cask: args.new_cask?, + token_conflicts: args.token_conflicts?, + quarantine: nil, + any_named_args: !no_named_args, + language: nil, + display_passes: args.verbose? || args.named.count == 1, + display_failures_only: args.display_failures_only?, ) end diff --git a/completions/bash/brew b/completions/bash/brew index 4a4c909696..b5b4ca46d8 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -324,6 +324,7 @@ _brew_audit() { --cask --debug --display-cop-names + --display-failures-only --display-filename --except --except-cops diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index 5f9d165a89..a370f05b03 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -325,6 +325,7 @@ __fish_brew_complete_arg 'audit' -l audit-debug -d 'Enable debugging and profili __fish_brew_complete_arg 'audit' -l cask -d 'Treat all named arguments as casks' __fish_brew_complete_arg 'audit' -l debug -d 'Display any debugging information' __fish_brew_complete_arg 'audit' -l display-cop-names -d 'Include the RuboCop cop name for each violation in the output' +__fish_brew_complete_arg 'audit' -l display-failures-only -d 'Only display casks that fail the audit. This is the default for formulae' __fish_brew_complete_arg 'audit' -l display-filename -d 'Prefix every line of output with the file or formula name being audited, to make output easy to grep' __fish_brew_complete_arg 'audit' -l except -d 'Specify a comma-separated method list to skip running the methods named `audit_`method' __fish_brew_complete_arg 'audit' -l except-cops -d 'Specify a comma-separated cops list to skip checking for violations of the listed RuboCop cops' diff --git a/completions/zsh/_brew b/completions/zsh/_brew index ccfb0b0820..743e086bb1 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -406,6 +406,7 @@ _brew_audit() { '--audit-debug[Enable debugging and profiling of audit methods]' \ '--debug[Display any debugging information]' \ '(--skip-style --only-cops --except-cops)--display-cop-names[Include the RuboCop cop name for each violation in the output]' \ + '--display-failures-only[Only display casks that fail the audit. This is the default for formulae]' \ '--display-filename[Prefix every line of output with the file or formula name being audited, to make output easy to grep]' \ '(--only)--except[Specify a comma-separated method list to skip running the methods named `audit_`method]' \ '(--only-cops --strict --only-cops --only --display-cop-names)--except-cops[Specify a comma-separated cops list to skip checking for violations of the listed RuboCop cops]' \ diff --git a/docs/Manpage.md b/docs/Manpage.md index 80537a5bbe..bf3c9e7cc0 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -780,6 +780,8 @@ non-zero status if any errors are found. Include the RuboCop cop name for each violation in the output. * `--display-filename`: Prefix every line of output with the file or formula name being audited, to make output easy to grep. +* `--display-failures-only`: + Only display casks that fail the audit. This is the default for formulae. * `--skip-style`: Skip running non-RuboCop style checks. Useful if you plan on running `brew style` separately. Enabled by default unless a formula is specified by name. * `-D`, `--audit-debug`: diff --git a/manpages/brew.1 b/manpages/brew.1 index 51e005c7c5..a592751b1d 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1062,6 +1062,10 @@ Include the RuboCop cop name for each violation in the output\. Prefix every line of output with the file or formula name being audited, to make output easy to grep\. . .TP +\fB\-\-display\-failures\-only\fR +Only display casks that fail the audit\. This is the default for formulae\. +. +.TP \fB\-\-skip\-style\fR Skip running non\-RuboCop style checks\. Useful if you plan on running \fBbrew style\fR separately\. Enabled by default unless a formula is specified by name\. .