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
|
require: ./Homebrew/rubocops.rb
|
||||||
|
|
||||||
Homebrew/CorrectBottleBlock:
|
FormulaAuditStrict/CorrectBottleBlock:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Homebrew/FormulaDesc:
|
FormulaAuditStrict/FormulaDesc:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Homebrew/FormulaComponentsOrder:
|
Homebrew/FormulaComponentsOrder:
|
||||||
|
|||||||
@ -56,8 +56,18 @@ module Homebrew
|
|||||||
]
|
]
|
||||||
args << "--auto-correct" if fix
|
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]
|
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
|
end
|
||||||
|
|
||||||
if files.nil?
|
if files.nil?
|
||||||
|
|||||||
@ -27,6 +27,10 @@
|
|||||||
#:
|
#:
|
||||||
#: If `--except` is passed, the methods named `audit_<method>` will not be run.
|
#: 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,
|
#: `audit` exits with a non-zero status if any errors are found. This is useful,
|
||||||
#: for instance, for implementing pre-commit hooks.
|
#: for instance, for implementing pre-commit hooks.
|
||||||
|
|
||||||
@ -69,17 +73,23 @@ module Homebrew
|
|||||||
files = ARGV.resolved_formulae.map(&:path)
|
files = ARGV.resolved_formulae.map(&:path)
|
||||||
end
|
end
|
||||||
|
|
||||||
if strict
|
only_cops = ARGV.value("only-cops").to_s.split(",")
|
||||||
options = { fix: ARGV.flag?("--fix"), realpath: true }
|
except_cops = ARGV.value("except-cops").to_s.split(",")
|
||||||
# Check style in a single batch run up front for performance
|
if !only_cops.empty? && !except_cops.empty?
|
||||||
style_results = check_style_json(files, options)
|
odie "--only-cops and --except-cops cannot be used simulataneously!"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !strict
|
if strict
|
||||||
options = { fix: ARGV.flag?("--fix"), realpath: true, only: :Homebrew }
|
options = { fix: ARGV.flag?("--fix"), realpath: true }
|
||||||
style_results = check_style_json(files, options)
|
else
|
||||||
|
options = { fix: ARGV.flag?("--fix"), realpath: true, exclude: :FormulaAuditStrict }
|
||||||
end
|
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|
|
ff.each do |f|
|
||||||
options = { new_formula: new_formula, strict: strict, online: online }
|
options = { new_formula: new_formula, strict: strict, online: online }
|
||||||
options[:style_offenses] = style_results.file_offenses(f.path)
|
options[:style_offenses] = style_results.file_offenses(f.path)
|
||||||
|
|||||||
@ -2,7 +2,7 @@ require_relative "./extend/formula_cop"
|
|||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Homebrew
|
module FormulaAuditStrict
|
||||||
# This cop audits `bottle` block in Formulae
|
# This cop audits `bottle` block in Formulae
|
||||||
#
|
#
|
||||||
# - `rebuild` should be used instead of `revision` in `bottle` block
|
# - `rebuild` should be used instead of `revision` in `bottle` block
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Homebrew
|
|
||||||
class FormulaCop < Cop
|
class FormulaCop < Cop
|
||||||
@registry = Cop.registry
|
@registry = Cop.registry
|
||||||
|
|
||||||
@ -210,5 +209,4 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require_relative "../extend/string"
|
|||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Homebrew
|
module FormulaAuditStrict
|
||||||
# This cop audits `desc` in Formulae
|
# This cop audits `desc` in Formulae
|
||||||
#
|
#
|
||||||
# - Checks for existence of `desc`
|
# - Checks for existence of `desc`
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require "rubocop/rspec/support"
|
|||||||
require_relative "../../extend/string"
|
require_relative "../../extend/string"
|
||||||
require_relative "../../rubocops/bottle_block_cop"
|
require_relative "../../rubocops/bottle_block_cop"
|
||||||
|
|
||||||
describe RuboCop::Cop::Homebrew::CorrectBottleBlock do
|
describe RuboCop::Cop::FormulaAuditStrict::CorrectBottleBlock do
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
context "When auditing Bottle Block" do
|
context "When auditing Bottle Block" do
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require "rubocop/rspec/support"
|
|||||||
require_relative "../../extend/string"
|
require_relative "../../extend/string"
|
||||||
require_relative "../../rubocops/formula_desc_cop"
|
require_relative "../../rubocops/formula_desc_cop"
|
||||||
|
|
||||||
describe RuboCop::Cop::Homebrew::FormulaDesc do
|
describe RuboCop::Cop::FormulaAuditStrict::FormulaDesc do
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
context "When auditing formula desc" do
|
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 `--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,
|
`audit` exits with a non-zero status if any errors are found. This is useful,
|
||||||
for instance, for implementing pre-commit hooks.
|
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\.
|
If \fB\-\-except\fR is passed, the methods named \fBaudit_<method>\fR will not be run\.
|
||||||
.
|
.
|
||||||
.IP
|
.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\.
|
\fBaudit\fR exits with a non\-zero status if any errors are found\. This is useful, for instance, for implementing pre\-commit hooks\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user