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:
Bo Anderson 2022-11-05 05:04:35 +00:00 committed by GitHub
commit 9b318a54d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 59 additions and 7 deletions

View File

@ -32,7 +32,7 @@ module Homebrew
if args.stackprof?
Homebrew.install_gem_setup_path! "stackprof"
with_env HOMEBREW_STACKPROF: "1" do
system RUBY_PATH, brew_rb, *args.named
system(*HOMEBREW_RUBY_EXEC_ARGS, brew_rb, *args.named)
end
output_filename = "prof/d3-flamegraph.html"
safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}"

View File

@ -75,9 +75,10 @@ module RuboCop
#
# @api private
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)
offending_node(class_node) if body_node.nil?
problem "A `test do` test block should be added"
end
end

View File

@ -15,6 +15,8 @@ module RuboCop
extend AutoCorrector
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)
component_problem @offensive_nodes[0], @offensive_nodes[1] if @offensive_nodes

View File

@ -20,6 +20,8 @@ module RuboCop
STABLE_MSG = "`stable do` should not be present without a `head` spec"
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.each do |url|

View File

@ -15,6 +15,8 @@ module RuboCop
"Use `keg_only :versioned_formula` instead."
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|
next unless parameters(conflicts_with_call).last.respond_to? :values

View File

@ -50,6 +50,8 @@ module RuboCop
#
# @param dependency_name dependency's name
def depends_on?(dependency_name, *types)
return if @body.nil?
types = [:any] if types.empty?
dependency_nodes = find_every_method_call_by_name(@body, :depends_on)
idx = dependency_nodes.index do |n|
@ -106,6 +108,8 @@ module RuboCop
# Return all the caveats' string nodes in an array.
def caveats_strings
return [] if @body.nil?
find_strings(find_method_def(@body, :caveats))
end

View File

@ -14,9 +14,10 @@ module RuboCop
include DescHelper
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
desc_call = find_node_method_by_name(body_node, :desc)
offending_node(class_node) if body_node.nil?
audit_desc(:formula, @name, desc_call)
end
end

View File

@ -10,10 +10,11 @@ module RuboCop
class Homepage < FormulaCop
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)
if homepage_node.nil?
offending_node(class_node) if body_node.nil?
problem "Formula should have a homepage."
return
end

View File

@ -91,6 +91,8 @@ module RuboCop
# @api private
class AssertStatements < FormulaCop
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|
if method_called_ever?(method, :include?) && !method_called_ever?(method, :!)
problem "Use `assert_match` instead of `assert ...include?`"
@ -116,6 +118,8 @@ module RuboCop
# @api private
class OptionDeclarations < FormulaCop
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)
if formula_tap == "homebrew-core"
@ -201,6 +205,8 @@ module RuboCop
extend AutoCorrector
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
return unless formula_tap == "homebrew-core"
@ -219,6 +225,8 @@ module RuboCop
# @api private
class PyoxidizerCheck < FormulaCop
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
return unless formula_tap == "homebrew-core"
@ -246,6 +254,8 @@ module RuboCop
extend AutoCorrector
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if body_node.nil?
test = find_block(body_node, :test)
[:popen_read, :popen_write].each do |unsafe_command|
@ -275,6 +285,8 @@ module RuboCop
extend AutoCorrector
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if body_node.nil?
popen_commands = [
:popen,
:popen_read,
@ -305,6 +317,8 @@ module RuboCop
extend AutoCorrector
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)
return unless license_node
@ -322,6 +336,8 @@ module RuboCop
# @api private
class Licenses < FormulaCop
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)
return unless license_node
return if license_node.source.include?("\n")
@ -345,6 +361,8 @@ module RuboCop
extend AutoCorrector
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|
string_content(parameters(dep).first).start_with? "python@"
end
@ -565,6 +583,8 @@ module RuboCop
# @api private
class Miscellaneous < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if body_node.nil?
# FileUtils is included in Formula
# encfs modifies a file with this name, so check for some leading characters
find_instance_method_call(body_node, "FileUtils", nil) do |method_node|

View File

@ -15,6 +15,8 @@ module RuboCop
OPTION = "Formulae in homebrew/core should not use `option`."
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.each do |option_call|
option = parameters(option_call).first

View File

@ -16,6 +16,8 @@ module RuboCop
def audit_formula(node, _class_node, _parent_class_node, body)
@full_source_content = source_buffer(node).source
return if body.nil?
external_patches = find_all_blocks(body, :patch)
external_patches.each do |patch_block|
url_node = find_every_method_call_by_name(patch_block, :url).first

View File

@ -22,6 +22,8 @@ module RuboCop
end
end
return if body_node.nil?
if !find_node_method_by_name(body_node, :plist_options) &&
find_method_def(body_node, :plist)
problem "Please set plist_options when using a formula-defined plist."
@ -106,6 +108,8 @@ module RuboCop
# @api private
class Text < FormulaCop
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
problem "`go_resource`s are deprecated. Please ask upstream to implement Go vendoring"
end

View File

@ -11,6 +11,8 @@ module RuboCop
# @api private
class Urls < FormulaCop
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)
mirrors = find_every_func_call_by_name(body_node, :mirror)
@ -262,6 +264,8 @@ module RuboCop
extend T::Sig
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)
mirrors = find_every_func_call_by_name(body_node, :mirror)
urls += mirrors
@ -292,6 +296,7 @@ module RuboCop
# @api private
class GitUrls < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if body_node.nil?
return unless formula_tap == "homebrew-core"
find_method_calls_by_name(body_node, :url).each do |url|
@ -315,6 +320,7 @@ module RuboCop
# @api private
class GitUrls < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if body_node.nil?
return unless formula_tap == "homebrew-core"
find_method_calls_by_name(body_node, :url).each do |url|

View File

@ -61,6 +61,8 @@ module RuboCop
].freeze
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
return if PROVIDED_BY_MACOS_FORMULAE.include? @formula_name
@ -94,6 +96,8 @@ module RuboCop
].freeze
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|
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
parameters(method).first

View File

@ -143,6 +143,7 @@ module Homebrew
FileUtils.rm_rf cache_env["XDG_CACHE_HOME"] if reset_cache
ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup
case output_type
when :print
args << "--debug" if debug
@ -153,11 +154,11 @@ module Homebrew
args << "--color" if Tty.color?
system cache_env, RUBY_PATH, RUBOCOP, *args
system cache_env, *ruby_args, "--", RUBOCOP, *args
$CHILD_STATUS.success?
when :json
result = system_command RUBY_PATH,
args: [RUBOCOP, "--format", "json", *args],
result = system_command ruby_args.shift,
args: [*ruby_args, "--", RUBOCOP, "--format", "json", *args],
env: cache_env
json = json_result!(result)
json["files"]