Merge pull request #14099 from Bo98/style-ruby-args
style: use HOMEBREW_RUBY_EXEC_ARGS, fix some cops erroring with empty formula body
This commit is contained in:
commit
9b318a54d0
@ -32,7 +32,7 @@ module Homebrew
|
|||||||
if args.stackprof?
|
if args.stackprof?
|
||||||
Homebrew.install_gem_setup_path! "stackprof"
|
Homebrew.install_gem_setup_path! "stackprof"
|
||||||
with_env HOMEBREW_STACKPROF: "1" do
|
with_env HOMEBREW_STACKPROF: "1" do
|
||||||
system RUBY_PATH, brew_rb, *args.named
|
system(*HOMEBREW_RUBY_EXEC_ARGS, brew_rb, *args.named)
|
||||||
end
|
end
|
||||||
output_filename = "prof/d3-flamegraph.html"
|
output_filename = "prof/d3-flamegraph.html"
|
||||||
safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}"
|
safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}"
|
||||||
|
@ -75,9 +75,10 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
class TestPresent < FormulaCop
|
class TestPresent < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, class_node, _parent_class_node, body_node)
|
||||||
return if find_block(body_node, :test)
|
return if find_block(body_node, :test)
|
||||||
|
|
||||||
|
offending_node(class_node) if body_node.nil?
|
||||||
problem "A `test do` test block should be added"
|
problem "A `test do` test block should be added"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,8 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
@present_components, @offensive_nodes = check_order(FORMULA_COMPONENT_PRECEDENCE_LIST, body_node)
|
@present_components, @offensive_nodes = check_order(FORMULA_COMPONENT_PRECEDENCE_LIST, body_node)
|
||||||
|
|
||||||
component_problem @offensive_nodes[0], @offensive_nodes[1] if @offensive_nodes
|
component_problem @offensive_nodes[0], @offensive_nodes[1] if @offensive_nodes
|
||||||
|
@ -20,6 +20,8 @@ module RuboCop
|
|||||||
STABLE_MSG = "`stable do` should not be present without a `head` spec"
|
STABLE_MSG = "`stable do` should not be present without a `head` spec"
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
urls = find_method_calls_by_name(body_node, :url)
|
urls = find_method_calls_by_name(body_node, :url)
|
||||||
|
|
||||||
urls.each do |url|
|
urls.each do |url|
|
||||||
|
@ -15,6 +15,8 @@ module RuboCop
|
|||||||
"Use `keg_only :versioned_formula` instead."
|
"Use `keg_only :versioned_formula` instead."
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
find_method_calls_by_name(body_node, :conflicts_with).each do |conflicts_with_call|
|
find_method_calls_by_name(body_node, :conflicts_with).each do |conflicts_with_call|
|
||||||
next unless parameters(conflicts_with_call).last.respond_to? :values
|
next unless parameters(conflicts_with_call).last.respond_to? :values
|
||||||
|
|
||||||
|
@ -50,6 +50,8 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# @param dependency_name dependency's name
|
# @param dependency_name dependency's name
|
||||||
def depends_on?(dependency_name, *types)
|
def depends_on?(dependency_name, *types)
|
||||||
|
return if @body.nil?
|
||||||
|
|
||||||
types = [:any] if types.empty?
|
types = [:any] if types.empty?
|
||||||
dependency_nodes = find_every_method_call_by_name(@body, :depends_on)
|
dependency_nodes = find_every_method_call_by_name(@body, :depends_on)
|
||||||
idx = dependency_nodes.index do |n|
|
idx = dependency_nodes.index do |n|
|
||||||
@ -106,6 +108,8 @@ module RuboCop
|
|||||||
|
|
||||||
# Return all the caveats' string nodes in an array.
|
# Return all the caveats' string nodes in an array.
|
||||||
def caveats_strings
|
def caveats_strings
|
||||||
|
return [] if @body.nil?
|
||||||
|
|
||||||
find_strings(find_method_def(@body, :caveats))
|
find_strings(find_method_def(@body, :caveats))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,9 +14,10 @@ module RuboCop
|
|||||||
include DescHelper
|
include DescHelper
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, class_node, _parent_class_node, body_node)
|
||||||
@name = @formula_name
|
@name = @formula_name
|
||||||
desc_call = find_node_method_by_name(body_node, :desc)
|
desc_call = find_node_method_by_name(body_node, :desc)
|
||||||
|
offending_node(class_node) if body_node.nil?
|
||||||
audit_desc(:formula, @name, desc_call)
|
audit_desc(:formula, @name, desc_call)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,10 +10,11 @@ module RuboCop
|
|||||||
class Homepage < FormulaCop
|
class Homepage < FormulaCop
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, class_node, _parent_class_node, body_node)
|
||||||
homepage_node = find_node_method_by_name(body_node, :homepage)
|
homepage_node = find_node_method_by_name(body_node, :homepage)
|
||||||
|
|
||||||
if homepage_node.nil?
|
if homepage_node.nil?
|
||||||
|
offending_node(class_node) if body_node.nil?
|
||||||
problem "Formula should have a homepage."
|
problem "Formula should have a homepage."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -91,6 +91,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class AssertStatements < FormulaCop
|
class AssertStatements < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
find_every_method_call_by_name(body_node, :assert).each do |method|
|
find_every_method_call_by_name(body_node, :assert).each do |method|
|
||||||
if method_called_ever?(method, :include?) && !method_called_ever?(method, :!)
|
if method_called_ever?(method, :include?) && !method_called_ever?(method, :!)
|
||||||
problem "Use `assert_match` instead of `assert ...include?`"
|
problem "Use `assert_match` instead of `assert ...include?`"
|
||||||
@ -116,6 +118,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class OptionDeclarations < FormulaCop
|
class OptionDeclarations < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
problem "Use new-style option definitions" if find_method_def(body_node, :options)
|
problem "Use new-style option definitions" if find_method_def(body_node, :options)
|
||||||
|
|
||||||
if formula_tap == "homebrew-core"
|
if formula_tap == "homebrew-core"
|
||||||
@ -201,6 +205,8 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
# Enforce use of OpenMPI for MPI dependency in core
|
# Enforce use of OpenMPI for MPI dependency in core
|
||||||
return unless formula_tap == "homebrew-core"
|
return unless formula_tap == "homebrew-core"
|
||||||
|
|
||||||
@ -219,6 +225,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class PyoxidizerCheck < FormulaCop
|
class PyoxidizerCheck < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
# Disallow use of PyOxidizer as a dependency in core
|
# Disallow use of PyOxidizer as a dependency in core
|
||||||
return unless formula_tap == "homebrew-core"
|
return unless formula_tap == "homebrew-core"
|
||||||
|
|
||||||
@ -246,6 +254,8 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
test = find_block(body_node, :test)
|
test = find_block(body_node, :test)
|
||||||
|
|
||||||
[:popen_read, :popen_write].each do |unsafe_command|
|
[:popen_read, :popen_write].each do |unsafe_command|
|
||||||
@ -275,6 +285,8 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
popen_commands = [
|
popen_commands = [
|
||||||
:popen,
|
:popen,
|
||||||
:popen_read,
|
:popen_read,
|
||||||
@ -305,6 +317,8 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
license_node = find_node_method_by_name(body_node, :license)
|
license_node = find_node_method_by_name(body_node, :license)
|
||||||
return unless license_node
|
return unless license_node
|
||||||
|
|
||||||
@ -322,6 +336,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class Licenses < FormulaCop
|
class Licenses < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
license_node = find_node_method_by_name(body_node, :license)
|
license_node = find_node_method_by_name(body_node, :license)
|
||||||
return unless license_node
|
return unless license_node
|
||||||
return if license_node.source.include?("\n")
|
return if license_node.source.include?("\n")
|
||||||
@ -345,6 +361,8 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
python_formula_node = find_every_method_call_by_name(body_node, :depends_on).find do |dep|
|
python_formula_node = find_every_method_call_by_name(body_node, :depends_on).find do |dep|
|
||||||
string_content(parameters(dep).first).start_with? "python@"
|
string_content(parameters(dep).first).start_with? "python@"
|
||||||
end
|
end
|
||||||
@ -565,6 +583,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class Miscellaneous < FormulaCop
|
class Miscellaneous < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
# FileUtils is included in Formula
|
# FileUtils is included in Formula
|
||||||
# encfs modifies a file with this name, so check for some leading characters
|
# encfs modifies a file with this name, so check for some leading characters
|
||||||
find_instance_method_call(body_node, "FileUtils", nil) do |method_node|
|
find_instance_method_call(body_node, "FileUtils", nil) do |method_node|
|
||||||
|
@ -15,6 +15,8 @@ module RuboCop
|
|||||||
OPTION = "Formulae in homebrew/core should not use `option`."
|
OPTION = "Formulae in homebrew/core should not use `option`."
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
option_call_nodes = find_every_method_call_by_name(body_node, :option)
|
option_call_nodes = find_every_method_call_by_name(body_node, :option)
|
||||||
option_call_nodes.each do |option_call|
|
option_call_nodes.each do |option_call|
|
||||||
option = parameters(option_call).first
|
option = parameters(option_call).first
|
||||||
|
@ -16,6 +16,8 @@ module RuboCop
|
|||||||
def audit_formula(node, _class_node, _parent_class_node, body)
|
def audit_formula(node, _class_node, _parent_class_node, body)
|
||||||
@full_source_content = source_buffer(node).source
|
@full_source_content = source_buffer(node).source
|
||||||
|
|
||||||
|
return if body.nil?
|
||||||
|
|
||||||
external_patches = find_all_blocks(body, :patch)
|
external_patches = find_all_blocks(body, :patch)
|
||||||
external_patches.each do |patch_block|
|
external_patches.each do |patch_block|
|
||||||
url_node = find_every_method_call_by_name(patch_block, :url).first
|
url_node = find_every_method_call_by_name(patch_block, :url).first
|
||||||
|
@ -22,6 +22,8 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
if !find_node_method_by_name(body_node, :plist_options) &&
|
if !find_node_method_by_name(body_node, :plist_options) &&
|
||||||
find_method_def(body_node, :plist)
|
find_method_def(body_node, :plist)
|
||||||
problem "Please set plist_options when using a formula-defined plist."
|
problem "Please set plist_options when using a formula-defined plist."
|
||||||
@ -106,6 +108,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class Text < FormulaCop
|
class Text < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
find_method_with_args(body_node, :go_resource) do
|
find_method_with_args(body_node, :go_resource) do
|
||||||
problem "`go_resource`s are deprecated. Please ask upstream to implement Go vendoring"
|
problem "`go_resource`s are deprecated. Please ask upstream to implement Go vendoring"
|
||||||
end
|
end
|
||||||
|
@ -11,6 +11,8 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class Urls < FormulaCop
|
class Urls < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
urls = find_every_func_call_by_name(body_node, :url)
|
urls = find_every_func_call_by_name(body_node, :url)
|
||||||
mirrors = find_every_func_call_by_name(body_node, :mirror)
|
mirrors = find_every_func_call_by_name(body_node, :mirror)
|
||||||
|
|
||||||
@ -262,6 +264,8 @@ module RuboCop
|
|||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
urls = find_every_func_call_by_name(body_node, :url)
|
urls = find_every_func_call_by_name(body_node, :url)
|
||||||
mirrors = find_every_func_call_by_name(body_node, :mirror)
|
mirrors = find_every_func_call_by_name(body_node, :mirror)
|
||||||
urls += mirrors
|
urls += mirrors
|
||||||
@ -292,6 +296,7 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class GitUrls < FormulaCop
|
class GitUrls < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
return unless formula_tap == "homebrew-core"
|
return unless formula_tap == "homebrew-core"
|
||||||
|
|
||||||
find_method_calls_by_name(body_node, :url).each do |url|
|
find_method_calls_by_name(body_node, :url).each do |url|
|
||||||
@ -315,6 +320,7 @@ module RuboCop
|
|||||||
# @api private
|
# @api private
|
||||||
class GitUrls < FormulaCop
|
class GitUrls < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
return unless formula_tap == "homebrew-core"
|
return unless formula_tap == "homebrew-core"
|
||||||
|
|
||||||
find_method_calls_by_name(body_node, :url).each do |url|
|
find_method_calls_by_name(body_node, :url).each do |url|
|
||||||
|
@ -61,6 +61,8 @@ module RuboCop
|
|||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
find_method_with_args(body_node, :keg_only, :provided_by_macos) do
|
find_method_with_args(body_node, :keg_only, :provided_by_macos) do
|
||||||
return if PROVIDED_BY_MACOS_FORMULAE.include? @formula_name
|
return if PROVIDED_BY_MACOS_FORMULAE.include? @formula_name
|
||||||
|
|
||||||
@ -94,6 +96,8 @@ module RuboCop
|
|||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
|
return if body_node.nil?
|
||||||
|
|
||||||
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
||||||
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
|
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
|
||||||
parameters(method).first
|
parameters(method).first
|
||||||
|
@ -143,6 +143,7 @@ module Homebrew
|
|||||||
|
|
||||||
FileUtils.rm_rf cache_env["XDG_CACHE_HOME"] if reset_cache
|
FileUtils.rm_rf cache_env["XDG_CACHE_HOME"] if reset_cache
|
||||||
|
|
||||||
|
ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup
|
||||||
case output_type
|
case output_type
|
||||||
when :print
|
when :print
|
||||||
args << "--debug" if debug
|
args << "--debug" if debug
|
||||||
@ -153,11 +154,11 @@ module Homebrew
|
|||||||
|
|
||||||
args << "--color" if Tty.color?
|
args << "--color" if Tty.color?
|
||||||
|
|
||||||
system cache_env, RUBY_PATH, RUBOCOP, *args
|
system cache_env, *ruby_args, "--", RUBOCOP, *args
|
||||||
$CHILD_STATUS.success?
|
$CHILD_STATUS.success?
|
||||||
when :json
|
when :json
|
||||||
result = system_command RUBY_PATH,
|
result = system_command ruby_args.shift,
|
||||||
args: [RUBOCOP, "--format", "json", *args],
|
args: [*ruby_args, "--", RUBOCOP, "--format", "json", *args],
|
||||||
env: cache_env
|
env: cache_env
|
||||||
json = json_result!(result)
|
json = json_result!(result)
|
||||||
json["files"]
|
json["files"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user