Add --only-cops,--except-cops options for brew audit
Also refactor audit cops into two "departments" - FormulaAudit - FormulaAuditStrict
This commit is contained in:
parent
a4568a8697
commit
c3330c289d
@ -8,10 +8,10 @@ AllCops:
|
||||
|
||||
require: ./Homebrew/rubocops.rb
|
||||
|
||||
Homebrew/CorrectBottleBlock:
|
||||
FormulaAuditStrict/CorrectBottleBlock:
|
||||
Enabled: true
|
||||
|
||||
Homebrew/FormulaDesc:
|
||||
FormulaAuditStrict/FormulaDesc:
|
||||
Enabled: true
|
||||
|
||||
Homebrew/FormulaComponentsOrder:
|
||||
|
||||
@ -56,8 +56,18 @@ module Homebrew
|
||||
]
|
||||
args << "--auto-correct" if fix
|
||||
|
||||
if options[:exclude].eql?(:FormulaAuditStrict) && !(options.key?(:except) || options.key?(:only))
|
||||
args << "--except" << :FormulaAuditStrict
|
||||
end
|
||||
|
||||
if options[:except]
|
||||
cops_to_exclude = options[:except].select { |cop| RuboCop::Cop::Cop.registry.names.include?(cop) }
|
||||
args << "--except" << cops_to_exclude.join(" ") unless cops_to_exclude.empty?
|
||||
end
|
||||
|
||||
if options[:only]
|
||||
args << "--only" << RuboCop::Cop::Cop.registry.with_department(options[:only]).names.join(" ")
|
||||
cops_to_include = options[:only].select { |cop| RuboCop::Cop::Cop.registry.names.include?(cop) }
|
||||
args << "--only" << cops_to_include.join(" ") unless cops_to_include.empty?
|
||||
end
|
||||
|
||||
if files.nil?
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
#:
|
||||
#: If `--except` is passed, the methods named `audit_<method>` will not be run.
|
||||
#:
|
||||
#: If `--only-cops` is passed, only the mentioned cops' violations would be checked.
|
||||
#:
|
||||
#: If `--except-cops` is passed, the mentioned cops' checks would be skipped.
|
||||
#:
|
||||
#: `audit` exits with a non-zero status if any errors are found. This is useful,
|
||||
#: for instance, for implementing pre-commit hooks.
|
||||
|
||||
@ -69,17 +73,23 @@ module Homebrew
|
||||
files = ARGV.resolved_formulae.map(&:path)
|
||||
end
|
||||
|
||||
if strict
|
||||
options = { fix: ARGV.flag?("--fix"), realpath: true }
|
||||
# Check style in a single batch run up front for performance
|
||||
style_results = check_style_json(files, options)
|
||||
only_cops = ARGV.value("only-cops").to_s.split(",")
|
||||
except_cops = ARGV.value("except-cops").to_s.split(",")
|
||||
if !only_cops.empty? && !except_cops.empty?
|
||||
odie "--only-cops and --except-cops cannot be used simulataneously!"
|
||||
end
|
||||
|
||||
if !strict
|
||||
options = { fix: ARGV.flag?("--fix"), realpath: true, only: :Homebrew }
|
||||
style_results = check_style_json(files, options)
|
||||
if strict
|
||||
options = { fix: ARGV.flag?("--fix"), realpath: true }
|
||||
else
|
||||
options = { fix: ARGV.flag?("--fix"), realpath: true, exclude: :FormulaAuditStrict }
|
||||
end
|
||||
|
||||
options[:only] = only_cops unless only_cops.empty?
|
||||
options[:except] = except_cops unless except_cops.empty?
|
||||
# Check style in a single batch run up front for performance
|
||||
style_results = check_style_json(files, options)
|
||||
|
||||
ff.each do |f|
|
||||
options = { new_formula: new_formula, strict: strict, online: online }
|
||||
options[:style_offenses] = style_results.file_offenses(f.path)
|
||||
|
||||
@ -2,7 +2,7 @@ require_relative "./extend/formula_cop"
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Homebrew
|
||||
module FormulaAuditStrict
|
||||
# This cop audits `bottle` block in Formulae
|
||||
#
|
||||
# - `rebuild` should be used instead of `revision` in `bottle` block
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Homebrew
|
||||
class FormulaCop < Cop
|
||||
@registry = Cop.registry
|
||||
|
||||
@ -210,5 +209,4 @@ module RuboCop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -3,7 +3,7 @@ require_relative "../extend/string"
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Homebrew
|
||||
module FormulaAuditStrict
|
||||
# This cop audits `desc` in Formulae
|
||||
#
|
||||
# - Checks for existence of `desc`
|
||||
|
||||
@ -3,7 +3,7 @@ require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/bottle_block_cop"
|
||||
|
||||
describe RuboCop::Cop::Homebrew::CorrectBottleBlock do
|
||||
describe RuboCop::Cop::FormulaAuditStrict::CorrectBottleBlock do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing Bottle Block" do
|
||||
|
||||
@ -3,7 +3,7 @@ require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/formula_desc_cop"
|
||||
|
||||
describe RuboCop::Cop::Homebrew::FormulaDesc do
|
||||
describe RuboCop::Cop::FormulaAuditStrict::FormulaDesc do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula desc" do
|
||||
|
||||
@ -635,6 +635,10 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note
|
||||
|
||||
If `--except` is passed, the methods named `audit_`method`` will not be run.
|
||||
|
||||
If `--only-cops` is passed, only the mentioned cops' violations would be checked.
|
||||
|
||||
If `--except-cops` is passed, the mentioned cops' checks would be skipped.
|
||||
|
||||
`audit` exits with a non-zero status if any errors are found. This is useful,
|
||||
for instance, for implementing pre-commit hooks.
|
||||
|
||||
|
||||
@ -662,6 +662,12 @@ If \fB\-\-only\fR is passed, only the methods named \fBaudit_<method>\fR will be
|
||||
If \fB\-\-except\fR is passed, the methods named \fBaudit_<method>\fR will not be run\.
|
||||
.
|
||||
.IP
|
||||
If \fB\-\-only\-cops\fR is passed, only the mentioned cops\' violations would be checked\.
|
||||
.
|
||||
.IP
|
||||
If \fB\-\-except\-cops\fR is passed, the mentioned cops\' checks would be skipped\.
|
||||
.
|
||||
.IP
|
||||
\fBaudit\fR exits with a non\-zero status if any errors are found\. This is useful, for instance, for implementing pre\-commit hooks\.
|
||||
.
|
||||
.TP
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user