Merge pull request #10896 from Rylan12/cask-audit-display-changes

audit: limit non-failure cask output
This commit is contained in:
Rylan Polster 2021-03-23 01:33:28 -04:00 committed by GitHub
commit 9a355b07c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 104 additions and 44 deletions

View File

@ -77,7 +77,7 @@ jobs:
run: brew style --display-cop-names homebrew/core run: brew style --display-cop-names homebrew/core
- name: Run brew audit --skip-style on all taps - 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 - name: Set up all Homebrew taps
run: | run: |
@ -277,10 +277,10 @@ jobs:
- name: Run brew audit --skip-style on Cask taps - name: Run brew audit --skip-style on Cask taps
run: | run: |
brew audit --skip-style --tap=homebrew/cask brew audit --skip-style --display-failures-only --tap=homebrew/cask
brew audit --skip-style --tap=homebrew/cask-drivers brew audit --skip-style --display-failures-only --tap=homebrew/cask-drivers
brew audit --skip-style --tap=homebrew/cask-fonts brew audit --skip-style --display-failures-only --tap=homebrew/cask-fonts
brew audit --skip-style --tap=homebrew/cask-versions brew audit --skip-style --display-failures-only --tap=homebrew/cask-versions
- name: Install brew tests dependencies - name: Install brew tests dependencies
run: | run: |

View File

@ -126,16 +126,21 @@ module Cask
end end
end end
sig { returns(String) } sig { params(include_passed: T::Boolean, include_warnings: T::Boolean).returns(String) }
def summary def summary(include_passed: false, include_warnings: true)
return if success? && !include_passed
return if warnings? && !errors? && !include_warnings
summary = ["audit for #{cask}: #{result}"] summary = ["audit for #{cask}: #{result}"]
errors.each do |error| errors.each do |error|
summary << " #{Formatter.error("-")} #{error}" summary << " #{Formatter.error("-")} #{error}"
end end
warnings.each do |warning| if include_warnings
summary << " #{Formatter.warning("-")} #{warning}" warnings.each do |warning|
summary << " #{Formatter.warning("-")} #{warning}"
end
end end
summary.join("\n") summary.join("\n")

View File

@ -18,7 +18,9 @@ module Cask
audit_token_conflicts: nil, audit_token_conflicts: nil,
quarantine: nil, quarantine: nil,
any_named_args: nil, any_named_args: nil,
language: nil language: nil,
display_passes: nil,
display_failures_only: nil
) )
new( new(
cask, cask,
@ -31,6 +33,8 @@ module Cask
quarantine: quarantine, quarantine: quarantine,
any_named_args: any_named_args, any_named_args: any_named_args,
language: language, language: language,
display_passes: display_passes,
display_failures_only: display_failures_only,
).audit ).audit
end end
@ -46,7 +50,9 @@ module Cask
audit_new_cask: nil, audit_new_cask: nil,
quarantine: nil, quarantine: nil,
any_named_args: nil, any_named_args: nil,
language: nil language: nil,
display_passes: nil,
display_failures_only: nil
) )
@cask = cask @cask = cask
@audit_download = audit_download @audit_download = audit_download
@ -58,6 +64,8 @@ module Cask
@audit_token_conflicts = audit_token_conflicts @audit_token_conflicts = audit_token_conflicts
@any_named_args = any_named_args @any_named_args = any_named_args
@language = language @language = language
@display_passes = display_passes
@display_failures_only = display_failures_only
end end
def audit def audit
@ -67,13 +75,18 @@ module Cask
if !language && language_blocks if !language && language_blocks
language_blocks.each_key do |l| language_blocks.each_key do |l|
audit = audit_languages(l) audit = audit_languages(l)
puts audit.summary if output_summary?(audit) summary = audit.summary(include_passed: output_passed?, include_warnings: output_warnings?)
if summary.present? && output_summary?(audit)
ohai "Auditing language: #{l.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary?
puts summary
end
warnings += audit.warnings warnings += audit.warnings
errors += audit.errors errors += audit.errors
end end
else else
audit = audit_cask_instance(cask) audit = audit_cask_instance(cask)
puts audit.summary if output_summary?(audit) summary = audit.summary(include_passed: output_passed?, include_warnings: output_warnings?)
puts summary if summary.present? && output_summary?(audit)
warnings += audit.warnings warnings += audit.warnings
errors += audit.errors errors += audit.errors
end end
@ -91,9 +104,20 @@ module Cask
audit.errors? audit.errors?
end end
def audit_languages(languages) def output_passed?
ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary? return false if @display_failures_only.present?
return true if @display_passes.present?
false
end
def output_warnings?
return false if @display_failures_only.present?
true
end
def audit_languages(languages)
original_config = cask.config original_config = cask.config
localized_config = original_config.merge(Config.new(explicit: { languages: languages })) localized_config = original_config.merge(Config.new(explicit: { languages: languages }))
cask.config = localized_config cask.config = localized_config

View File

@ -27,6 +27,8 @@ module Cask
description: "Run various additional style checks to determine if a new cask is eligible " \ 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 " \ "for Homebrew. This should be used when creating new casks and implies " \
"`--strict` and `--online`" "`--strict` and `--online`"
switch "--display-failures-only",
description: "Only display casks that fail the audit. This is the default for formulae."
end end
end end
@ -44,15 +46,17 @@ module Cask
results = self.class.audit_casks( results = self.class.audit_casks(
*casks, *casks,
download: args.download?, download: args.download?,
appcast: args.appcast?, appcast: args.appcast?,
online: args.online?, online: args.online?,
strict: args.strict?, strict: args.strict?,
new_cask: args.new_cask?, new_cask: args.new_cask?,
token_conflicts: args.token_conflicts?, token_conflicts: args.token_conflicts?,
quarantine: args.quarantine?, quarantine: args.quarantine?,
any_named_args: any_named_args, any_named_args: any_named_args,
language: args.language, language: args.language,
display_passes: args.verbose? || args.named.count == 1,
display_failures_only: args.display_failures_only?,
) )
self.class.print_annotations(results) self.class.print_annotations(results)
@ -73,7 +77,9 @@ module Cask
token_conflicts: nil, token_conflicts: nil,
quarantine: nil, quarantine: nil,
any_named_args: nil, any_named_args: nil,
language: nil language: nil,
display_passes: nil,
display_failures_only: nil
) )
options = { options = {
audit_download: download, audit_download: download,
@ -85,6 +91,8 @@ module Cask
quarantine: quarantine, quarantine: quarantine,
language: language, language: language,
any_named_args: any_named_args, any_named_args: any_named_args,
display_passes: display_passes,
display_failures_only: display_failures_only,
}.compact }.compact
options[:quarantine] = true if options[:quarantine].nil? options[:quarantine] = true if options[:quarantine].nil?

View File

@ -56,6 +56,8 @@ module Homebrew
switch "--display-filename", switch "--display-filename",
description: "Prefix every line of output with the file or formula name being audited, to "\ description: "Prefix every line of output with the file or formula name being audited, to "\
"make output easy to grep." "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", switch "--skip-style",
description: "Skip running non-RuboCop style checks. Useful if you plan on running "\ 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." "`brew style` separately. Enabled by default unless a formula is specified by name."
@ -213,15 +215,17 @@ module Homebrew
Cask::Cmd::Audit.audit_casks( Cask::Cmd::Audit.audit_casks(
*audit_casks, *audit_casks,
download: nil, download: nil,
appcast: args.appcast?, appcast: args.appcast?,
online: args.online?, online: args.online?,
strict: args.strict?, strict: args.strict?,
new_cask: args.new_cask?, new_cask: args.new_cask?,
token_conflicts: args.token_conflicts?, token_conflicts: args.token_conflicts?,
quarantine: nil, quarantine: nil,
any_named_args: !no_named_args, any_named_args: !no_named_args,
language: nil, language: nil,
display_passes: args.verbose? || args.named.count == 1,
display_failures_only: args.display_failures_only?,
) )
end end

View File

@ -21,7 +21,8 @@ describe Cask::Cmd::Audit, :cask do
expect(Cask::CaskLoader).to receive(:load).with(cask_token, any_args).and_return(cask) expect(Cask::CaskLoader).to receive(:load).with(cask_token, any_args).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_new_cask: false, quarantine: true, any_named_args: true) .with(cask, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run(cask_token) described_class.run(cask_token)
@ -31,7 +32,8 @@ describe Cask::Cmd::Audit, :cask do
it "does not pass anything if no flags are specified" do it "does not pass anything if no flags are specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_new_cask: false, quarantine: true, any_named_args: true) .with(cask, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken") described_class.run("casktoken")
@ -40,7 +42,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `audit_download` if the `--download` flag is specified" do it "passes `audit_download` if the `--download` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_download: true, audit_new_cask: false, quarantine: true, any_named_args: true) .with(cask, audit_download: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--download") described_class.run("casktoken", "--download")
@ -49,7 +52,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `audit_token_conflicts` if the `--token-conflicts` flag is specified" do it "passes `audit_token_conflicts` if the `--token-conflicts` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_token_conflicts: true, audit_new_cask: false, quarantine: true, any_named_args: true) .with(cask, audit_token_conflicts: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--token-conflicts") described_class.run("casktoken", "--token-conflicts")
@ -58,7 +62,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `audit_strict` if the `--strict` flag is specified" do it "passes `audit_strict` if the `--strict` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_strict: true, audit_new_cask: false, quarantine: true, any_named_args: true) .with(cask, audit_strict: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--strict") described_class.run("casktoken", "--strict")
@ -67,7 +72,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `audit_online` if the `--online` flag is specified" do it "passes `audit_online` if the `--online` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_online: true, audit_new_cask: false, quarantine: true, any_named_args: true) .with(cask, audit_online: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--online") described_class.run("casktoken", "--online")
@ -76,7 +82,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `audit_new_cask` if the `--new-cask` flag is specified" do it "passes `audit_new_cask` if the `--new-cask` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_new_cask: true, quarantine: true, any_named_args: true) .with(cask, audit_new_cask: true, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--new-cask") described_class.run("casktoken", "--new-cask")
@ -85,7 +92,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `language` if the `--language` flag is specified" do it "passes `language` if the `--language` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_new_cask: false, quarantine: true, language: ["de-AT"], any_named_args: true) .with(cask, audit_new_cask: false, quarantine: true, language: ["de-AT"], any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--language=de-AT") described_class.run("casktoken", "--language=de-AT")
@ -94,7 +102,8 @@ describe Cask::Cmd::Audit, :cask do
it "passes `quarantine` if the `--no-quarantine` flag is specified" do it "passes `quarantine` if the `--no-quarantine` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_new_cask: false, quarantine: false, any_named_args: true) .with(cask, audit_new_cask: false, quarantine: false, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken", "--no-quarantine") described_class.run("casktoken", "--no-quarantine")
@ -105,7 +114,8 @@ describe Cask::Cmd::Audit, :cask do
allow(Cask::CaskLoader).to receive(:load).and_return(cask) allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit) expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_new_cask: false, quarantine: false, any_named_args: true) .with(cask, audit_new_cask: false, quarantine: false, any_named_args: true,
display_failures_only: false, display_passes: true)
.and_return(result) .and_return(result)
described_class.run("casktoken") described_class.run("casktoken")

View File

@ -324,6 +324,7 @@ _brew_audit() {
--cask --cask
--debug --debug
--display-cop-names --display-cop-names
--display-failures-only
--display-filename --display-filename
--except --except
--except-cops --except-cops

View File

@ -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 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 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-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 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 -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' __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'

View File

@ -406,6 +406,7 @@ _brew_audit() {
'--audit-debug[Enable debugging and profiling of audit methods]' \ '--audit-debug[Enable debugging and profiling of audit methods]' \
'--debug[Display any debugging information]' \ '--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]' \ '(--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]' \ '--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)--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]' \ '(--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]' \

View File

@ -780,6 +780,8 @@ non-zero status if any errors are found.
Include the RuboCop cop name for each violation in the output. Include the RuboCop cop name for each violation in the output.
* `--display-filename`: * `--display-filename`:
Prefix every line of output with the file or formula name being audited, to make output easy to grep. 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-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. 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`: * `-D`, `--audit-debug`:

View File

@ -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\. Prefix every line of output with the file or formula name being audited, to make output easy to grep\.
. .
.TP .TP
\fB\-\-display\-failures\-only\fR
Only display casks that fail the audit\. This is the default for formulae\.
.
.TP
\fB\-\-skip\-style\fR \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\. 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\.
. .