diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 9d97b00d1a..12c94bf94f 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -622,7 +622,7 @@ module Cask if referenced_cask skip_info = Homebrew::Livecheck::SkipConditions.referenced_skip_information( referenced_cask, - Homebrew::Livecheck.cask_name(cask), + Homebrew::Livecheck.package_or_resource_name(cask), ) end diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index c5739a6cb1..dcb45e7b5a 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -13,18 +13,18 @@ module Homebrew # command. These methods print the requested livecheck information # for formulae. module Livecheck - module_function - GITEA_INSTANCES = T.let(%w[ codeberg.org gitea.com opendev.org tildegit.org ].freeze, T::Array[String]) + private_constant :GITEA_INSTANCES GOGS_INSTANCES = T.let(%w[ lolg.it ].freeze, T::Array[String]) + private_constant :GOGS_INSTANCES STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL = T.let([ :extract_plist, @@ -36,6 +36,7 @@ module Homebrew :xml, :yaml, ].freeze, T::Array[Symbol]) + private_constant :STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL UNSTABLE_VERSION_KEYWORDS = T.let(%w[ alpha @@ -47,9 +48,10 @@ module Homebrew preview rc ].freeze, T::Array[String]) + private_constant :UNSTABLE_VERSION_KEYWORDS sig { returns(T::Hash[T::Class[T.anything], String]) } - def livecheck_strategy_names + private_class_method def self.livecheck_strategy_names return T.must(@livecheck_strategy_names) if defined?(@livecheck_strategy_names) # Cache demodulized strategy names, to avoid repeating this work @@ -66,7 +68,7 @@ module Homebrew # Uses `formulae_and_casks_to_check` to identify taps in use other than # homebrew/core and homebrew/cask and loads strategies from them. sig { params(formulae_and_casks_to_check: T::Array[T.any(Formula, Cask::Cask)]).void } - def load_other_tap_strategies(formulae_and_casks_to_check) + def self.load_other_tap_strategies(formulae_and_casks_to_check) other_taps = {} formulae_and_casks_to_check.each do |formula_or_cask| next if formula_or_cask.tap.blank? @@ -95,7 +97,7 @@ module Homebrew debug: T::Boolean, ).returns(T.nilable(T::Array[T.untyped])) } - def resolve_livecheck_reference( + def self.resolve_livecheck_reference( formula_or_cask, first_formula_or_cask = formula_or_cask, references = [], @@ -170,7 +172,7 @@ module Homebrew verbose: T::Boolean, ).void } - def run_checks( + def self.run_checks( formulae_and_casks_to_check, full_name: false, handle_name_conflict: false, check_resources: false, json: false, newer_only: false, extract_plist: false, debug: false, quiet: false, verbose: false @@ -432,7 +434,7 @@ module Homebrew end sig { params(package_or_resource: T.any(Formula, Cask::Cask, Resource), full_name: T::Boolean).returns(String) } - def package_or_resource_name(package_or_resource, full_name: false) + def self.package_or_resource_name(package_or_resource, full_name: false) case package_or_resource when Formula formula_name(package_or_resource, full_name:) @@ -448,14 +450,14 @@ module Homebrew # Returns the fully-qualified name of a cask if the `full_name` argument is # provided; returns the name otherwise. sig { params(cask: Cask::Cask, full_name: T::Boolean).returns(String) } - def cask_name(cask, full_name: false) + private_class_method def self.cask_name(cask, full_name: false) full_name ? cask.full_name : cask.token end # Returns the fully-qualified name of a formula if the `full_name` argument is # provided; returns the name otherwise. sig { params(formula: Formula, full_name: T::Boolean).returns(String) } - def formula_name(formula, full_name: false) + private_class_method def self.formula_name(formula, full_name: false) full_name ? formula.full_name : formula.name end @@ -468,7 +470,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def status_hash(package_or_resource, status_str, messages = nil, full_name: false, verbose: false) + def self.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) cask = package_or_resource if package_or_resource.is_a?(Cask::Cask) resource = package_or_resource if package_or_resource.is_a?(Resource) @@ -494,7 +496,7 @@ module Homebrew # Formats and prints the livecheck result for a formula/cask/resource. 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) + private_class_method def self.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}" package_or_resource_s += " (cask)" if ambiguous_cask @@ -517,7 +519,7 @@ module Homebrew # Prints the livecheck result for the resources of a given Formula. sig { params(info: T::Array[T::Hash[Symbol, T.untyped]], verbose: T::Boolean).void } - def print_resources_info(info, verbose: false) + private_class_method def self.print_resources_info(info, verbose: false) info.each do |r_info| if r_info[:status] && r_info[:messages] SkipConditions.print_skip_information(r_info) @@ -533,7 +535,7 @@ module Homebrew package_or_resource: T.any(Formula, Cask::Cask, Resource), ).returns(T.nilable(String)) } - def livecheck_url_to_string(livecheck_url, package_or_resource) + def self.livecheck_url_to_string(livecheck_url, package_or_resource) case livecheck_url when String livecheck_url @@ -548,7 +550,7 @@ module Homebrew # Returns an Array containing the formula/cask/resource URLs that can be used by livecheck. sig { params(package_or_resource: T.any(Formula, Cask::Cask, Resource)).returns(T::Array[String]) } - def checkable_urls(package_or_resource) + def self.checkable_urls(package_or_resource) urls = [] case package_or_resource @@ -573,7 +575,7 @@ module Homebrew # Preprocesses and returns the URL used by livecheck. sig { params(url: String).returns(String) } - def preprocess_url(url) + def self.preprocess_url(url) begin uri = Addressable::URI.parse url rescue Addressable::URI::InvalidURIError @@ -617,7 +619,7 @@ module Homebrew # contains a `stable`/`url` or `head` URL `using: :homebrew_curl` that # shares the same root domain. sig { params(formula_or_cask: T.any(Formula, Cask::Cask), url: String).returns(T::Boolean) } - def use_homebrew_curl?(formula_or_cask, url) + def self.use_homebrew_curl?(formula_or_cask, url) url_root_domain = Addressable::URI.parse(url)&.domain return false if url_root_domain.blank? @@ -655,7 +657,7 @@ module Homebrew debug: T::Boolean, ).returns(T.nilable(T::Hash[Symbol, T.untyped])) } - def latest_version( + def self.latest_version( formula_or_cask, referenced_formula_or_cask: nil, livecheck_references: [], @@ -674,13 +676,12 @@ module Homebrew livecheck_strategy_block = livecheck.strategy_block || referenced_livecheck&.strategy_block livecheck_throttle = livecheck.throttle || referenced_livecheck&.throttle - livecheck_url_string = livecheck_url_to_string( - livecheck_url, - referenced_formula_or_cask || formula_or_cask, - ) + referenced_package = referenced_formula_or_cask || formula_or_cask + + livecheck_url_string = livecheck_url_to_string(livecheck_url, referenced_package) if livecheck_url urls = [livecheck_url_string] if livecheck_url_string - urls ||= checkable_urls(referenced_formula_or_cask || formula_or_cask) + urls ||= checkable_urls(referenced_package) if debug if formula @@ -751,7 +752,7 @@ module Homebrew homebrew_curl = case strategy_name when "PageMatch", "HeaderMatch" - use_homebrew_curl?((referenced_formula_or_cask || formula_or_cask), url) + use_homebrew_curl?(referenced_package, url) end puts "Homebrew curl?: Yes" if debug && homebrew_curl.present? @@ -888,7 +889,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def resource_version( + def self.resource_version( resource, formula_latest, json: false, diff --git a/Library/Homebrew/livecheck/livecheck.rbi b/Library/Homebrew/livecheck/livecheck.rbi deleted file mode 100644 index b47d360b80..0000000000 --- a/Library/Homebrew/livecheck/livecheck.rbi +++ /dev/null @@ -1,11 +0,0 @@ -# typed: strict - -module Homebrew - module Livecheck - include ::Kernel - - module SkipConditions - include ::Kernel - end - end -end diff --git a/Library/Homebrew/livecheck/skip_conditions.rb b/Library/Homebrew/livecheck/skip_conditions.rb index ab8139e319..e8fc9a9ebd 100644 --- a/Library/Homebrew/livecheck/skip_conditions.rb +++ b/Library/Homebrew/livecheck/skip_conditions.rb @@ -6,8 +6,6 @@ module Homebrew # The `Livecheck::SkipConditions` module primarily contains methods that # check for various formula/cask/resource conditions where a check should be skipped. module SkipConditions - module_function - sig { params( package_or_resource: T.any(Formula, Cask::Cask, Resource), @@ -16,7 +14,12 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def package_or_resource_skip(package_or_resource, livecheckable, full_name: false, verbose: false) + private_class_method def self.package_or_resource_skip( + package_or_resource, + livecheckable, + full_name: false, + verbose: false + ) formula = package_or_resource if package_or_resource.is_a?(Formula) if (stable_url = formula&.stable&.url) @@ -53,7 +56,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def formula_head_only(formula, _livecheckable, full_name: false, verbose: false) + private_class_method def self.formula_head_only(formula, _livecheckable, full_name: false, verbose: false) return {} if !formula.head_only? || formula.any_version_installed? Livecheck.status_hash( @@ -73,7 +76,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def formula_deprecated(formula, livecheckable, full_name: false, verbose: false) + private_class_method def self.formula_deprecated(formula, livecheckable, full_name: false, verbose: false) return {} if !formula.deprecated? || livecheckable Livecheck.status_hash(formula, "deprecated", full_name:, verbose:) @@ -87,7 +90,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def formula_disabled(formula, livecheckable, full_name: false, verbose: false) + private_class_method def self.formula_disabled(formula, livecheckable, full_name: false, verbose: false) return {} if !formula.disabled? || livecheckable Livecheck.status_hash(formula, "disabled", full_name:, verbose:) @@ -101,7 +104,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def formula_versioned(formula, livecheckable, full_name: false, verbose: false) + private_class_method def self.formula_versioned(formula, livecheckable, full_name: false, verbose: false) return {} if !formula.versioned_formula? || livecheckable Livecheck.status_hash(formula, "versioned", full_name:, verbose:) @@ -115,7 +118,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def cask_deprecated(cask, livecheckable, full_name: false, verbose: false) + private_class_method def self.cask_deprecated(cask, livecheckable, full_name: false, verbose: false) return {} if !cask.deprecated? || livecheckable Livecheck.status_hash(cask, "deprecated", full_name:, verbose:) @@ -129,7 +132,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def cask_disabled(cask, livecheckable, full_name: false, verbose: false) + private_class_method def self.cask_disabled(cask, livecheckable, full_name: false, verbose: false) return {} if !cask.disabled? || livecheckable Livecheck.status_hash(cask, "disabled", full_name:, verbose:) @@ -144,7 +147,13 @@ module Homebrew extract_plist: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def cask_extract_plist(cask, _livecheckable, full_name: false, verbose: false, extract_plist: false) + private_class_method def self.cask_extract_plist( + cask, + _livecheckable, + full_name: false, + verbose: false, + extract_plist: false + ) return {} if extract_plist || cask.livecheck.strategy != :extract_plist Livecheck.status_hash( @@ -164,7 +173,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def cask_version_latest(cask, livecheckable, full_name: false, verbose: false) + private_class_method def self.cask_version_latest(cask, livecheckable, full_name: false, verbose: false) return {} if !(cask.present? && cask.version&.latest?) || livecheckable Livecheck.status_hash(cask, "latest", full_name:, verbose:) @@ -178,7 +187,7 @@ module Homebrew verbose: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false) + private_class_method def self.cask_url_unversioned(cask, livecheckable, full_name: false, verbose: false) return {} if !(cask.present? && cask.url&.unversioned?) || livecheckable Livecheck.status_hash(cask, "unversioned", full_name:, verbose:) @@ -192,6 +201,7 @@ module Homebrew :formula_disabled, :formula_versioned, ].freeze, T::Array[Symbol]) + private_constant :FORMULA_CHECKS # Skip conditions for casks. CASK_CHECKS = T.let([ @@ -202,11 +212,13 @@ module Homebrew :cask_version_latest, :cask_url_unversioned, ].freeze, T::Array[Symbol]) + private_constant :CASK_CHECKS # Skip conditions for resources. RESOURCE_CHECKS = T.let([ :package_or_resource_skip, ].freeze, T::Array[Symbol]) + private_constant :RESOURCE_CHECKS # If a formula/cask/resource should be skipped, we return a hash from # `Livecheck#status_hash`, which contains a `status` type and sometimes @@ -219,7 +231,7 @@ module Homebrew extract_plist: T::Boolean, ).returns(T::Hash[Symbol, T.untyped]) } - def skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true) + def self.skip_information(package_or_resource, full_name: false, verbose: false, extract_plist: true) livecheckable = package_or_resource.livecheckable? checks = case package_or_resource @@ -257,7 +269,7 @@ module Homebrew extract_plist: T::Boolean, ).returns(T.nilable(T::Hash[Symbol, T.untyped])) } - def referenced_skip_information( + def self.referenced_skip_information( livecheck_package_or_resource, original_package_or_resource_name, full_name: false, @@ -299,7 +311,7 @@ module Homebrew # Prints default livecheck output in relation to skip conditions. sig { params(skip_hash: T::Hash[Symbol, T.untyped]).void } - def print_skip_information(skip_hash) + def self.print_skip_information(skip_hash) return unless skip_hash.is_a?(Hash) name = if skip_hash[:formula].is_a?(String) diff --git a/Library/Homebrew/test/livecheck/livecheck_spec.rb b/Library/Homebrew/test/livecheck/livecheck_spec.rb index 34e048f510..1e18dfe666 100644 --- a/Library/Homebrew/test/livecheck/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck/livecheck_spec.rb @@ -65,23 +65,21 @@ RSpec.describe Homebrew::Livecheck do end end - describe "::formula_name" do - it "returns the name of the formula" do - expect(livecheck.formula_name(f)).to eq("test") + describe "::package_or_resource_name" do + it "returns the name of a formula" do + expect(livecheck.package_or_resource_name(f)).to eq("test") end - it "returns the full name" do - expect(livecheck.formula_name(f, full_name: true)).to eq("test") - end - end - - describe "::cask_name" do - it "returns the token of the cask" do - expect(livecheck.cask_name(c)).to eq("test") + it "returns the full name of a formula" do + expect(livecheck.package_or_resource_name(f, full_name: true)).to eq("test") end - it "returns the full name of the cask" do - expect(livecheck.cask_name(c, full_name: true)).to eq("test") + it "returns the token of a cask" do + expect(livecheck.package_or_resource_name(c)).to eq("test") + end + + it "returns the full name of a cask" do + expect(livecheck.package_or_resource_name(c, full_name: true)).to eq("test") end end @@ -169,9 +167,6 @@ RSpec.describe Homebrew::Livecheck do end it "returns nil when not given a string or valid symbol" do - expect(livecheck.livecheck_url_to_string(nil, f_livecheck_url)).to be_nil - expect(livecheck.livecheck_url_to_string(nil, c_livecheck_url)).to be_nil - expect(livecheck.livecheck_url_to_string(nil, r_livecheck_url)).to be_nil expect(livecheck.livecheck_url_to_string(:invalid_symbol, f_livecheck_url)).to be_nil expect(livecheck.livecheck_url_to_string(:invalid_symbol, c_livecheck_url)).to be_nil expect(livecheck.livecheck_url_to_string(:invalid_symbol, r_livecheck_url)).to be_nil diff --git a/Library/Homebrew/test/livecheck/skip_conditions_spec.rb b/Library/Homebrew/test/livecheck/skip_conditions_spec.rb index 6c5347164d..7187ef7dad 100644 --- a/Library/Homebrew/test/livecheck/skip_conditions_spec.rb +++ b/Library/Homebrew/test/livecheck/skip_conditions_spec.rb @@ -650,10 +650,6 @@ RSpec.describe Homebrew::Livecheck::SkipConditions do expect { skip_conditions.print_skip_information({}) } .to not_to_output.to_stdout .and not_to_output.to_stderr - - expect { skip_conditions.print_skip_information(nil) } - .to not_to_output.to_stdout - .and not_to_output.to_stderr end end end