From c75fc63d6108286c01072af78b1bcafc834a45ca Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 12 Dec 2023 10:09:49 -0800 Subject: [PATCH 1/6] refactor out except! calls --- Library/Homebrew/livecheck/livecheck.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index dd198c7d804f5..8dc86c7935059 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -321,7 +321,12 @@ def run_checks( latest_info = status_hash(formula_or_cask, "error", [no_versions_msg], full_name: use_full_name, verbose: verbose) if check_for_resources - resource_version_info.map! { |r| r.except!(:meta) } unless verbose + unless verbose + resource_version_info.map! do |r| + r.delete(:meta) + r + end + end latest_info[:resources] = resource_version_info end @@ -368,8 +373,13 @@ def run_checks( if json progress&.increment - info.except!(:meta) unless verbose - resource_version_info.map! { |r| r.except!(:meta) } if check_for_resources && !verbose + info.delete(:meta) unless verbose + if check_for_resources && !verbose + resource_version_info.map! do |r| + r.delete(:meta) + r + end + end next info end puts if debug From e8d87fe256ec09dd531fb347f77af9c8313d289e Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 12 Dec 2023 10:10:18 -0800 Subject: [PATCH 2/6] Strict type livecheck/livecheck --- Library/Homebrew/livecheck/livecheck.rb | 39 +++++++++++++------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 8dc86c7935059..a23717d3fce8a 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "livecheck/constants" @@ -18,18 +18,18 @@ module Homebrew module Livecheck module_function - GITEA_INSTANCES = %w[ + GITEA_INSTANCES = T.let(%w[ codeberg.org gitea.com opendev.org tildegit.org - ].freeze + ].freeze, T::Array[String]) - GOGS_INSTANCES = %w[ + GOGS_INSTANCES = T.let(%w[ lolg.it - ].freeze + ].freeze, T::Array[String]) - STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = [ + STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = T.let([ :extract_plist, :github_latest, :header_match, @@ -38,9 +38,9 @@ module Livecheck :sparkle, :xml, :yaml, - ].freeze + ].freeze, T::Array[Symbol]) - UNSTABLE_VERSION_KEYWORDS = %w[ + UNSTABLE_VERSION_KEYWORDS = T.let(%w[ alpha beta bpo @@ -49,21 +49,21 @@ module Livecheck prerelease preview rc - ].freeze + ].freeze, T::Array[String]) sig { returns(T::Hash[Class, String]) } def livecheck_strategy_names - return @livecheck_strategy_names if defined?(@livecheck_strategy_names) + return T.must(@livecheck_strategy_names) if defined?(@livecheck_strategy_names) # Cache demodulized strategy names, to avoid repeating this work - @livecheck_strategy_names = {} + @livecheck_strategy_names = T.let({}, T.nilable(T::Hash[Class, String])) Strategy.constants.sort.each do |const_symbol| constant = Strategy.const_get(const_symbol) next unless constant.is_a?(Class) - @livecheck_strategy_names[constant] = Utils.demodulize(T.must(constant.name)) + T.must(@livecheck_strategy_names)[constant] = Utils.demodulize(T.must(constant.name)) end - @livecheck_strategy_names.freeze + T.must(@livecheck_strategy_names).freeze end # Uses `formulae_and_casks_to_check` to identify taps in use other than @@ -83,7 +83,7 @@ def load_other_tap_strategies(formulae_and_casks_to_check) other_taps.each_value do |tap| tap_strategy_path = "#{tap.path}/livecheck/strategy" - Dir["#{tap_strategy_path}/*.rb"].sort.each(&method(:require)) if Dir.exist?(tap_strategy_path) + Dir["#{tap_strategy_path}/*.rb"].sort.each { require(_1) } if Dir.exist?(tap_strategy_path) end end @@ -456,7 +456,7 @@ def formula_name(formula, full_name: false) messages: T.nilable(T::Array[String]), full_name: T::Boolean, verbose: T::Boolean, - ).returns(Hash) + ).returns(T::Hash[Symbol, T.untyped]) } def status_hash(package_or_resource, status_str, messages = nil, full_name: false, verbose: false) formula = package_or_resource if package_or_resource.is_a?(Formula) @@ -483,7 +483,7 @@ def status_hash(package_or_resource, status_str, messages = nil, full_name: fals end # Formats and prints the livecheck result for a formula/cask/resource. - sig { params(info: Hash, verbose: T::Boolean, ambiguous_cask: T::Boolean).void } + sig { params(info: T::Hash[Symbol, T.untyped], verbose: T::Boolean, ambiguous_cask: T::Boolean).void } def print_latest_version(info, verbose: false, ambiguous_cask: false) package_or_resource_s = info[:resource].present? ? " " : "" package_or_resource_s += "#{Tty.blue}#{info[:formula] || info[:cask] || info[:resource]}#{Tty.reset}" @@ -506,7 +506,7 @@ def print_latest_version(info, verbose: false, ambiguous_cask: false) end # Prints the livecheck result for the resources of a given Formula. - sig { params(info: T::Array[Hash], verbose: T::Boolean).void } + sig { params(info: T::Array[T::Hash[Symbol, T.untyped]], verbose: T::Boolean).void } def print_resources_info(info, verbose: false) info.each do |r_info| if r_info[:status] && r_info[:messages] @@ -643,7 +643,7 @@ def use_homebrew_curl?(formula_or_cask, url) full_name: T::Boolean, verbose: T::Boolean, debug: T::Boolean, - ).returns(T.nilable(Hash)) + ).returns(T.nilable(T::Hash[Symbol, T.untyped])) } def latest_version( formula_or_cask, @@ -844,6 +844,7 @@ def latest_version( end nil end + # Identifies the latest version of a resource and returns a Hash containing the # version information. Returns nil if a latest version couldn't be found. sig { @@ -854,7 +855,7 @@ def latest_version( debug: T::Boolean, quiet: T::Boolean, verbose: T::Boolean, - ).returns(Hash) + ).returns(T::Hash[Symbol, T.untyped]) } def resource_version( resource, From 7ebee52614cff6f8adf0e898d8691ae0093454f6 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 12 Dec 2023 10:12:01 -0800 Subject: [PATCH 3/6] Remove monkey-patched Hash#except --- Library/Homebrew/global.rb | 1 - .../active_support/core_ext/hash/except.rb | 24 ------------------- 2 files changed, 25 deletions(-) delete mode 100644 Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/except.rb diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index ea6f1ebec47dd..084d74abee315 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -16,7 +16,6 @@ require "active_support/core_ext/enumerable" require "active_support/core_ext/file/atomic" require "active_support/core_ext/hash/deep_merge" -require "active_support/core_ext/hash/except" require "active_support/core_ext/hash/keys" require "active_support/core_ext/string/exclude" require "active_support/core_ext/string/filters" diff --git a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/except.rb b/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/except.rb deleted file mode 100644 index ec96929b0ae6b..0000000000000 --- a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/except.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -class Hash - # Returns a hash that includes everything except given keys. - # hash = { a: true, b: false, c: nil } - # hash.except(:c) # => { a: true, b: false } - # hash.except(:a, :b) # => { c: nil } - # hash # => { a: true, b: false, c: nil } - # - # This is useful for limiting a set of parameters to everything but a few known toggles: - # @person.update(params[:person].except(:admin)) - def except(*keys) - slice(*self.keys - keys) - end unless method_defined?(:except) - - # Removes the given keys from hash and returns it. - # hash = { a: true, b: false, c: nil } - # hash.except!(:c) # => { a: true, b: false } - # hash # => { a: true, b: false } - def except!(*keys) - keys.each { |key| delete(key) } - self - end -end From 2f22ad40c8c6cd5025a48da2ff9ca019599cf588 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 12 Dec 2023 10:12:35 -0800 Subject: [PATCH 4/6] Add h Hash#except to gitignore list --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e990476891ce9..7e6379d8f3643 100644 --- a/.gitignore +++ b/.gitignore @@ -68,7 +68,6 @@ !**/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/except.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/keys.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/slice.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb From 4a062b117cd1bf4db702d5bb41ef2563a0962ff2 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 12 Dec 2023 10:19:58 -0800 Subject: [PATCH 5/6] Rename block var --- Library/Homebrew/livecheck/livecheck.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index a23717d3fce8a..a5471a3b984d2 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -322,9 +322,9 @@ def run_checks( verbose: verbose) if check_for_resources unless verbose - resource_version_info.map! do |r| - r.delete(:meta) - r + resource_version_info.map! do |info| + info.delete(:meta) + info end end latest_info[:resources] = resource_version_info @@ -375,9 +375,9 @@ def run_checks( progress&.increment info.delete(:meta) unless verbose if check_for_resources && !verbose - resource_version_info.map! do |r| - r.delete(:meta) - r + resource_version_info.map! do |info| + info.delete(:meta) + info end end next info From 0ce84387fd8bccab9f87472b98036ed5197d326b Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 12 Dec 2023 10:40:08 -0800 Subject: [PATCH 6/6] Also remove Hash#slice! --- .gitignore | 1 - .../Homebrew/dev-cmd/update-maintainers.rb | 4 +-- .../lib/active_support/core_ext/hash/slice.rb | 27 ------------------- 3 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/slice.rb diff --git a/.gitignore b/.gitignore index 7e6379d8f3643..eb1ff5afc9425 100644 --- a/.gitignore +++ b/.gitignore @@ -69,7 +69,6 @@ !**/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/hash/slice.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb diff --git a/Library/Homebrew/dev-cmd/update-maintainers.rb b/Library/Homebrew/dev-cmd/update-maintainers.rb index 6df75822db795..8bdeb0fd46b5c 100644 --- a/Library/Homebrew/dev-cmd/update-maintainers.rb +++ b/Library/Homebrew/dev-cmd/update-maintainers.rb @@ -5,8 +5,6 @@ require "utils/github" require "manpages" -require "active_support/core_ext/hash/slice" - module Homebrew module_function @@ -39,7 +37,7 @@ def update_maintainers sentences = {} members.each do |group, hash| - hash.slice!(*public_members) + hash.replace(hash.slice(*public_members)) hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" } sentences[group] = hash.values.sort.to_sentence end diff --git a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/slice.rb b/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/slice.rb deleted file mode 100644 index 56bc5de382e68..0000000000000 --- a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/hash/slice.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -class Hash - # Replaces the hash with only the given keys. - # Returns a hash containing the removed key/value pairs. - # - # hash = { a: 1, b: 2, c: 3, d: 4 } - # hash.slice!(:a, :b) # => {:c=>3, :d=>4} - # hash # => {:a=>1, :b=>2} - def slice!(*keys) - omit = slice(*self.keys - keys) - hash = slice(*keys) - hash.default = default - hash.default_proc = default_proc if default_proc - replace(hash) - omit - end - - # Removes and returns the key/value pairs matching the given keys. - # - # hash = { a: 1, b: 2, c: 3, d: 4 } - # hash.extract!(:a, :b) # => {:a=>1, :b=>2} - # hash # => {:c=>3, :d=>4} - def extract!(*keys) - keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) } - end -end