Add --fix option to brew audit command
This commit is contained in:
parent
483c40fb03
commit
0b3d9031e2
@ -1,11 +1,14 @@
|
|||||||
#: * `audit` [`--strict`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [<formulae>]:
|
#: * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [<formulae>]:
|
||||||
#: Check <formulae> for Homebrew coding style violations. This should be
|
#: Check <formulae> for Homebrew coding style violations. This should be
|
||||||
#: run before submitting a new formula.
|
#: run before submitting a new formula.
|
||||||
#:
|
#:
|
||||||
#: If no <formulae> are provided, all of them are checked.
|
#: If no <formulae> are provided, all of them are checked.
|
||||||
#:
|
#:
|
||||||
#: If `--strict` is passed, additional checks are run, including RuboCop
|
#: If `--strict` is passed, additional checks are run, including RuboCop
|
||||||
#: style checks.
|
#: style checks and custom cop checks.
|
||||||
|
#:
|
||||||
|
#: If `--fix` is passed, style violations and custom cop violations will be
|
||||||
|
#: automatically fixed using RuboCop's `--auto-correct` feature.
|
||||||
#:
|
#:
|
||||||
#: If `--online` is passed, additional slower checks that require a network
|
#: If `--online` is passed, additional slower checks that require a network
|
||||||
#: connection are run.
|
#: connection are run.
|
||||||
@ -62,8 +65,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
if strict
|
if strict
|
||||||
|
options = { fix: ARGV.flag?("--fix"), realpath: true }
|
||||||
# Check style in a single batch run up front for performance
|
# Check style in a single batch run up front for performance
|
||||||
style_results = check_style_json(files, realpath: true)
|
style_results = check_style_json(files, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
ff.each do |f|
|
ff.each do |f|
|
||||||
|
@ -1,36 +1,34 @@
|
|||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module CustomCops
|
module CustomCops
|
||||||
class CorrectBottleBlock < Cop
|
class CorrectBottleBlock < Cop
|
||||||
MSG = 'Use rebuild instead of revision in bottle block'.freeze
|
MSG = "Use rebuild instead of revision in bottle block".freeze
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return if block_length(node).zero?
|
return if block_length(node).zero?
|
||||||
method, _args, _body = *node
|
method, _args, body = *node
|
||||||
|
_keyword, method_name = *method
|
||||||
|
|
||||||
keyword, method_name = *method
|
return unless method_name.equal?(:bottle) && revision?(body)
|
||||||
|
add_offense(node, :expression)
|
||||||
if method_name.equal?(:bottle) and has_revision?(_body)
|
|
||||||
add_offense(node, :expression)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def autocorrect(node)
|
def autocorrect(node)
|
||||||
->(corrector) do
|
lambda do |corrector|
|
||||||
# Check for revision
|
# Check for revision
|
||||||
method, _args, _body = *node
|
_method, _args, body = *node
|
||||||
if has_revision?(_body)
|
if revision?(body)
|
||||||
replace_revision(corrector, node)
|
replace_revision(corrector, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_revision?(body)
|
def revision?(body)
|
||||||
body.children.each do |method_call_node|
|
body.children.each do |method_call_node|
|
||||||
_receiver, _method_name, *args = *method_call_node
|
_receiver, method_name, _args = *method_call_node
|
||||||
if _method_name == :revision
|
if method_name == :revision
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -38,10 +36,10 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def replace_revision(corrector, node)
|
def replace_revision(corrector, node)
|
||||||
new_source = String.new
|
new_source = ""
|
||||||
node.source.each_line do |line|
|
node.source.each_line do |line|
|
||||||
if line =~ /\A\s*revision/
|
if line =~ /\A\s*revision/
|
||||||
line = line.sub('revision','rebuild')
|
line = line.sub("revision", "rebuild")
|
||||||
end
|
end
|
||||||
new_source << line
|
new_source << line
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user