diff --git a/.gitignore b/.gitignore index 99eef04e54..f4692e2200 100644 --- a/.gitignore +++ b/.gitignore @@ -63,8 +63,6 @@ !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/ !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/ !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/*/ -!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/file/atomic.rb -!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_transform_values.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/keys.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 524674708d..7ebc235b33 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -11,6 +11,7 @@ require "utils/inreplace" require "erb" require "utils/gzip" require "api" +require "extend/hash/deep_merge" BOTTLE_ERB = <<-EOS.freeze bottle do diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index 971a191e72..5f6fa25633 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -5,6 +5,7 @@ require "cli/parser" require "formula" require "github_packages" require "github_releases" +require "extend/hash/deep_merge" module Homebrew module_function diff --git a/Library/Homebrew/extend/array.rb b/Library/Homebrew/extend/array.rb index 0163a2bb7f..152033304b 100644 --- a/Library/Homebrew/extend/array.rb +++ b/Library/Homebrew/extend/array.rb @@ -17,6 +17,11 @@ class Array # %w( a b c d e ).fourth # => "d" def fourth = self[3] + # Equal to self[4]. + # + # %w( a b c d e ).fifth # => "e" + def fifth = self[4] + # Converts the array to a comma-separated sentence where the last element is # joined by the connector word. # diff --git a/Library/Homebrew/extend/array.rbi b/Library/Homebrew/extend/array.rbi index 0c1bb89dd7..3d9e293bd4 100644 --- a/Library/Homebrew/extend/array.rbi +++ b/Library/Homebrew/extend/array.rbi @@ -9,4 +9,7 @@ class Array sig { returns(T.nilable(Elem)) } def fourth; end + + sig { returns(T.nilable(Elem)) } + def fifth; end end diff --git a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/deep_merge.rb b/Library/Homebrew/extend/hash/deep_merge.rb similarity index 81% rename from Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/deep_merge.rb rename to Library/Homebrew/extend/hash/deep_merge.rb index 9bc50b7bc6..01ecbe9260 100644 --- a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/deep_merge.rb +++ b/Library/Homebrew/extend/hash/deep_merge.rb @@ -1,3 +1,4 @@ +# typed: strict # frozen_string_literal: true class Hash @@ -22,10 +23,10 @@ class Hash # Same as +deep_merge+, but modifies +self+. def deep_merge!(other_hash, &block) merge!(other_hash) do |key, this_val, other_val| - if this_val.is_a?(Hash) && other_val.is_a?(Hash) - this_val.deep_merge(other_val, &block) - elsif block_given? - block.call(key, this_val, other_val) + if T.unsafe(this_val).is_a?(Hash) && other_val.is_a?(Hash) + T.unsafe(this_val).deep_merge(other_val, &block) + elsif block + yield(key, this_val, other_val) else other_val end diff --git a/Library/Homebrew/extend/hash/deep_merge.rbi b/Library/Homebrew/extend/hash/deep_merge.rbi new file mode 100644 index 0000000000..ed5f3a9b6c --- /dev/null +++ b/Library/Homebrew/extend/hash/deep_merge.rbi @@ -0,0 +1,20 @@ +# typed: strict +# frozen_string_literal: true + +class Hash + sig do + type_parameters(:k2).params( + other_hash: T::Hash[T.type_parameter(:k2), T.untyped], + block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)) + ).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped]) + end + def deep_merge(other_hash, &block); end + + sig do + type_parameters(:k2).params( + other_hash: T::Hash[T.type_parameter(:k2), T.untyped], + block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)) + ).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped]) + end + def deep_merge!(other_hash, &block); end +end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 6bc52c9433..20e0482bb2 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -10,7 +10,6 @@ require "json/add/exception" require "forwardable" require "set" -require "active_support/core_ext/hash/deep_merge" require "active_support/core_ext/hash/keys" HOMEBREW_API_DEFAULT_DOMAIN = ENV.fetch("HOMEBREW_API_DEFAULT_DOMAIN").freeze diff --git a/Library/Homebrew/test/rubocop_spec.rb b/Library/Homebrew/test/rubocop_spec.rb index ce163c2d98..dbf055d8fd 100644 --- a/Library/Homebrew/test/rubocop_spec.rb +++ b/Library/Homebrew/test/rubocop_spec.rb @@ -17,7 +17,7 @@ describe "RuboCop" do end it "loads all Formula cops without errors" do - stdout, stderr, status = Open3.capture3(RUBY_PATH, "-W0", "-S", "rubocop", TEST_FIXTURE_DIR/"testball.rb") + stdout, stderr, status = Open3.capture3(RUBY_PATH, "-W0", "-S", "rubocop", "-d", TEST_FIXTURE_DIR/"testball.rb") expect(stderr).to be_empty expect(stdout).to include("no offenses detected") expect(status).to be_a_success