From e03548fc7a7ef3774a00e0f34eb0ea6b18b80b00 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sat, 5 Nov 2022 03:05:58 +0000 Subject: [PATCH 1/3] style: use HOMEBREW_RUBY_EXEC_ARGS --- Library/Homebrew/style.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index cdbabeb93f..e3a7c763b7 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -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"] From a54b7a8c15370c77266ae36f37b21b7c66f7a2b1 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sat, 5 Nov 2022 03:06:10 +0000 Subject: [PATCH 2/3] dev-cmd/prof: use HOMEBREW_RUBY_EXEC_ARGS --- Library/Homebrew/dev-cmd/prof.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/prof.rb b/Library/Homebrew/dev-cmd/prof.rb index d5b100c165..dfc7f1ae18 100644 --- a/Library/Homebrew/dev-cmd/prof.rb +++ b/Library/Homebrew/dev-cmd/prof.rb @@ -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}" From 6ede5d2dd5cf378729669dc02e8b324b86986dde Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sat, 5 Nov 2022 04:17:50 +0000 Subject: [PATCH 3/3] rubocops: handle empty formula body in various cops --- Library/Homebrew/rubocops/class.rb | 3 ++- Library/Homebrew/rubocops/components_order.rb | 2 ++ .../rubocops/components_redundancy.rb | 2 ++ Library/Homebrew/rubocops/conflicts.rb | 2 ++ Library/Homebrew/rubocops/extend/formula.rb | 4 ++++ Library/Homebrew/rubocops/formula_desc.rb | 3 ++- Library/Homebrew/rubocops/homepage.rb | 3 ++- Library/Homebrew/rubocops/lines.rb | 20 +++++++++++++++++++ Library/Homebrew/rubocops/options.rb | 2 ++ Library/Homebrew/rubocops/patches.rb | 2 ++ Library/Homebrew/rubocops/text.rb | 4 ++++ Library/Homebrew/rubocops/urls.rb | 6 ++++++ Library/Homebrew/rubocops/uses_from_macos.rb | 4 ++++ 13 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/rubocops/class.rb b/Library/Homebrew/rubocops/class.rb index bea3bc055f..4ed2192b04 100644 --- a/Library/Homebrew/rubocops/class.rb +++ b/Library/Homebrew/rubocops/class.rb @@ -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 diff --git a/Library/Homebrew/rubocops/components_order.rb b/Library/Homebrew/rubocops/components_order.rb index eac9cc91e7..d4becfa86f 100644 --- a/Library/Homebrew/rubocops/components_order.rb +++ b/Library/Homebrew/rubocops/components_order.rb @@ -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 diff --git a/Library/Homebrew/rubocops/components_redundancy.rb b/Library/Homebrew/rubocops/components_redundancy.rb index 767306c759..cf2067a701 100644 --- a/Library/Homebrew/rubocops/components_redundancy.rb +++ b/Library/Homebrew/rubocops/components_redundancy.rb @@ -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| diff --git a/Library/Homebrew/rubocops/conflicts.rb b/Library/Homebrew/rubocops/conflicts.rb index 35bcf87096..757c6b5e95 100644 --- a/Library/Homebrew/rubocops/conflicts.rb +++ b/Library/Homebrew/rubocops/conflicts.rb @@ -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 diff --git a/Library/Homebrew/rubocops/extend/formula.rb b/Library/Homebrew/rubocops/extend/formula.rb index d4b09bab73..89c513997f 100644 --- a/Library/Homebrew/rubocops/extend/formula.rb +++ b/Library/Homebrew/rubocops/extend/formula.rb @@ -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 diff --git a/Library/Homebrew/rubocops/formula_desc.rb b/Library/Homebrew/rubocops/formula_desc.rb index 11dfefd3b0..771951f962 100644 --- a/Library/Homebrew/rubocops/formula_desc.rb +++ b/Library/Homebrew/rubocops/formula_desc.rb @@ -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 diff --git a/Library/Homebrew/rubocops/homepage.rb b/Library/Homebrew/rubocops/homepage.rb index 700060ed81..bae5437105 100644 --- a/Library/Homebrew/rubocops/homepage.rb +++ b/Library/Homebrew/rubocops/homepage.rb @@ -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 diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 683d27f720..051a33688d 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -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| diff --git a/Library/Homebrew/rubocops/options.rb b/Library/Homebrew/rubocops/options.rb index a255297eab..817399e05b 100644 --- a/Library/Homebrew/rubocops/options.rb +++ b/Library/Homebrew/rubocops/options.rb @@ -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 diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index 79ffc873c6..34518d1092 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -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 diff --git a/Library/Homebrew/rubocops/text.rb b/Library/Homebrew/rubocops/text.rb index 67a6f70f2c..1908efe3be 100644 --- a/Library/Homebrew/rubocops/text.rb +++ b/Library/Homebrew/rubocops/text.rb @@ -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 diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index 67860051d4..a9c10176dc 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -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| diff --git a/Library/Homebrew/rubocops/uses_from_macos.rb b/Library/Homebrew/rubocops/uses_from_macos.rb index d719d42e1d..d21adfd8af 100644 --- a/Library/Homebrew/rubocops/uses_from_macos.rb +++ b/Library/Homebrew/rubocops/uses_from_macos.rb @@ -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