dev-cmd/audit: add --skip-style option.
This will allow `brew style` and `brew audit` to be run separately without providing duplicates. Additionally, run RuboCop style rules when `--strict` isn't provided and remove a confusing reference to `style`.
This commit is contained in:
parent
957b404ee7
commit
5e2351cde6
@ -26,9 +26,9 @@ module Homebrew
|
|||||||
found, which can be useful for implementing pre-commit hooks.
|
found, which can be useful for implementing pre-commit hooks.
|
||||||
EOS
|
EOS
|
||||||
switch "--strict",
|
switch "--strict",
|
||||||
description: "Run additional style checks, including RuboCop style checks."
|
description: "Run additional, stricter style checks."
|
||||||
switch "--online",
|
switch "--online",
|
||||||
description: "Run additional slower style checks that require a network connection."
|
description: "Run additional, slower style checks that require a network connection."
|
||||||
switch "--new-formula",
|
switch "--new-formula",
|
||||||
description: "Run various additional style checks to determine if a new formula is eligible "\
|
description: "Run various additional style checks to determine if a new formula is eligible "\
|
||||||
"for Homebrew. This should be used when creating new formula and implies "\
|
"for Homebrew. This should be used when creating new formula and implies "\
|
||||||
@ -40,6 +40,9 @@ 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 "--skip-style",
|
||||||
|
description: "Skip running non-RuboCop style checks. Useful if you plan on running "\
|
||||||
|
"`brew style` separately."
|
||||||
switch "-D", "--audit-debug",
|
switch "-D", "--audit-debug",
|
||||||
description: "Enable debugging and profiling of audit methods."
|
description: "Enable debugging and profiling of audit methods."
|
||||||
comma_array "--only",
|
comma_array "--only",
|
||||||
@ -59,6 +62,9 @@ module Homebrew
|
|||||||
conflicts "--only", "--except"
|
conflicts "--only", "--except"
|
||||||
conflicts "--only-cops", "--except-cops", "--strict"
|
conflicts "--only-cops", "--except-cops", "--strict"
|
||||||
conflicts "--only-cops", "--except-cops", "--only"
|
conflicts "--only-cops", "--except-cops", "--only"
|
||||||
|
conflicts "--display-cop-names", "--skip-style"
|
||||||
|
conflicts "--display-cop-names", "--only-cops"
|
||||||
|
conflicts "--display-cop-names", "--except-cops"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -80,11 +86,11 @@ module Homebrew
|
|||||||
ENV.setup_build_environment
|
ENV.setup_build_environment
|
||||||
|
|
||||||
if args.no_named?
|
if args.no_named?
|
||||||
ff = Formula
|
audit_formulae = Formula
|
||||||
files = Tap.map(&:formula_dir)
|
style_files = Tap.map(&:formula_dir)
|
||||||
else
|
else
|
||||||
ff = args.resolved_formulae
|
audit_formulae = args.resolved_formulae
|
||||||
files = args.formulae_paths
|
style_files = args.formulae_paths
|
||||||
end
|
end
|
||||||
|
|
||||||
only_cops = args.only_cops
|
only_cops = args.only_cops
|
||||||
@ -98,17 +104,17 @@ module Homebrew
|
|||||||
elsif except_cops
|
elsif except_cops
|
||||||
options[:except_cops] = except_cops
|
options[:except_cops] = except_cops
|
||||||
elsif !strict
|
elsif !strict
|
||||||
options[:only_cops] = [:FormulaAudit]
|
options[:except_cops] = [:FormulaAuditStrict]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check style in a single batch run up front for performance
|
# Check style in a single batch run up front for performance
|
||||||
style_results = Style.check_style_json(files, options)
|
style_results = Style.check_style_json(style_files, options) unless args.skip_style?
|
||||||
|
|
||||||
new_formula_problem_lines = []
|
new_formula_problem_lines = []
|
||||||
ff.sort.each do |f|
|
audit_formulae.sort.each do |f|
|
||||||
only = only_cops ? ["style"] : args.only
|
only = only_cops ? ["style"] : args.only
|
||||||
options = { new_formula: new_formula, strict: strict, online: online, only: only, except: args.except }
|
options = { new_formula: new_formula, strict: strict, online: online, only: only, except: args.except }
|
||||||
options[:style_offenses] = style_results.file_offenses(f.path)
|
options[:style_offenses] = style_results.file_offenses(f.path) unless args.skip_style?
|
||||||
options[:display_cop_names] = args.display_cop_names?
|
options[:display_cop_names] = args.display_cop_names?
|
||||||
|
|
||||||
fa = FormulaAuditor.new(f, options)
|
fa = FormulaAuditor.new(f, options)
|
||||||
@ -119,7 +125,7 @@ module Homebrew
|
|||||||
formula_count += 1
|
formula_count += 1
|
||||||
problem_count += fa.problems.size
|
problem_count += fa.problems.size
|
||||||
problem_lines = format_problem_lines(fa.problems)
|
problem_lines = format_problem_lines(fa.problems)
|
||||||
corrected_problem_count = options[:style_offenses].count(&:corrected?)
|
corrected_problem_count = options[:style_offenses].count(&:corrected?) unless args.skip_style?
|
||||||
new_formula_problem_lines = format_problem_lines(fa.new_formula_problems)
|
new_formula_problem_lines = format_problem_lines(fa.new_formula_problems)
|
||||||
if args.display_filename?
|
if args.display_filename?
|
||||||
puts problem_lines.map { |s| "#{f.path}: #{s}" }
|
puts problem_lines.map { |s| "#{f.path}: #{s}" }
|
||||||
@ -451,7 +457,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def audit_keg_only_style
|
def audit_keg_only
|
||||||
return unless formula.keg_only?
|
return unless formula.keg_only?
|
||||||
|
|
||||||
whitelist = %w[
|
whitelist = %w[
|
||||||
|
@ -353,7 +353,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#audit_keg_only_style" do
|
describe "#audit_keg_only" do
|
||||||
specify "keg_only_needs_downcasing" do
|
specify "keg_only_needs_downcasing" do
|
||||||
fa = formula_auditor "foo", <<~RUBY, strict: true
|
fa = formula_auditor "foo", <<~RUBY, strict: true
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -363,7 +363,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
fa.audit_keg_only_style
|
fa.audit_keg_only
|
||||||
expect(fa.problems)
|
expect(fa.problems)
|
||||||
.to eq(["'Because' from the keg_only reason should be 'because'.\n"])
|
.to eq(["'Because' from the keg_only reason should be 'because'.\n"])
|
||||||
end
|
end
|
||||||
@ -377,7 +377,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
fa.audit_keg_only_style
|
fa.audit_keg_only
|
||||||
expect(fa.problems)
|
expect(fa.problems)
|
||||||
.to eq(["keg_only reason should not end with a period."])
|
.to eq(["keg_only reason should not end with a period."])
|
||||||
end
|
end
|
||||||
@ -396,7 +396,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
fa.audit_keg_only_style
|
fa.audit_keg_only
|
||||||
expect(fa.problems)
|
expect(fa.problems)
|
||||||
.to eq([])
|
.to eq([])
|
||||||
end
|
end
|
||||||
@ -410,7 +410,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
fa.audit_keg_only_style
|
fa.audit_keg_only
|
||||||
expect(fa.problems)
|
expect(fa.problems)
|
||||||
.to eq([])
|
.to eq([])
|
||||||
end
|
end
|
||||||
|
@ -633,9 +633,9 @@ available formulae. Will exit with a non-zero status if any errors are found,
|
|||||||
which can be useful for implementing pre-commit hooks.
|
which can be useful for implementing pre-commit hooks.
|
||||||
|
|
||||||
* `--strict`:
|
* `--strict`:
|
||||||
Run additional style checks, including RuboCop style checks.
|
Run additional, stricter style checks.
|
||||||
* `--online`:
|
* `--online`:
|
||||||
Run additional slower style checks that require a network connection.
|
Run additional, slower style checks that require a network connection.
|
||||||
* `--new-formula`:
|
* `--new-formula`:
|
||||||
Run various additional style checks to determine if a new formula is eligible for Homebrew. This should be used when creating new formula and implies `--strict` and `--online`.
|
Run various additional style checks to determine if a new formula is eligible for Homebrew. This should be used when creating new formula and implies `--strict` and `--online`.
|
||||||
* `--fix`:
|
* `--fix`:
|
||||||
@ -644,6 +644,8 @@ which can be useful for implementing pre-commit hooks.
|
|||||||
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.
|
||||||
|
* `--skip-style`:
|
||||||
|
Skip running non-RuboCop style checks. Useful if you plan on running `brew style` separately.
|
||||||
* `-D`, `--audit-debug`:
|
* `-D`, `--audit-debug`:
|
||||||
Enable debugging and profiling of audit methods.
|
Enable debugging and profiling of audit methods.
|
||||||
* `--only`:
|
* `--only`:
|
||||||
|
@ -799,11 +799,11 @@ Check \fIformula\fR for Homebrew coding style violations\. This should be run be
|
|||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-strict\fR
|
\fB\-\-strict\fR
|
||||||
Run additional style checks, including RuboCop style checks\.
|
Run additional, stricter style checks\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-online\fR
|
\fB\-\-online\fR
|
||||||
Run additional slower style checks that require a network connection\.
|
Run additional, slower style checks that require a network connection\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-new\-formula\fR
|
\fB\-\-new\-formula\fR
|
||||||
@ -822,6 +822,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\-\-skip\-style\fR
|
||||||
|
Skip running non\-RuboCop style checks\. Useful if you plan on running \fBbrew style\fR separately\.
|
||||||
|
.
|
||||||
|
.TP
|
||||||
\fB\-D\fR, \fB\-\-audit\-debug\fR
|
\fB\-D\fR, \fB\-\-audit\-debug\fR
|
||||||
Enable debugging and profiling of audit methods\.
|
Enable debugging and profiling of audit methods\.
|
||||||
.
|
.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user