diff --git a/Library/Homebrew/cask/artifact/relocated.rb b/Library/Homebrew/cask/artifact/relocated.rb index 0642db0e2b..97bc0e8dda 100644 --- a/Library/Homebrew/cask/artifact/relocated.rb +++ b/Library/Homebrew/cask/artifact/relocated.rb @@ -13,7 +13,7 @@ module Cask source_string, target_hash = args if target_hash - raise CaskInvalidError unless target_hash.respond_to?(:keys) + raise CaskInvalidError.new(cask) unless target_hash.respond_to?(:keys) target_hash.assert_valid_keys(:target) end diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index ae3533e7a8..b546a44f48 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -78,6 +78,8 @@ module Cask key = k.to_sym if DEFAULT_DIRS.key?(key) + raise TypeError, "Invalid path for default dir #{k}: #{v.inspect}" if v.is_a?(Array) + [key, Pathname(v).expand_path] else [key, v] diff --git a/Library/Homebrew/cask/url.rb b/Library/Homebrew/cask/url.rb index db93901c5b..fd4865f313 100644 --- a/Library/Homebrew/cask/url.rb +++ b/Library/Homebrew/cask/url.rb @@ -236,7 +236,7 @@ module Cask def raw_url_line return @raw_url_line if defined?(@raw_url_line) - @raw_url_line = Pathname(@caller_location.path) + @raw_url_line = Pathname(T.must(@caller_location.path)) .each_line .drop(@caller_location.lineno - 1) .first diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index b5fd1544de..6eef639aa9 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -320,7 +320,7 @@ module Homebrew next unless tap.installed? if tap.git_branch == "master" && - (Date.parse(tap.git_repo.last_commit_date) <= Date.today.prev_month) + (Date.parse(T.must(tap.git_repo.last_commit_date)) <= Date.today.prev_month) ohai "#{tap.name} is old and unneeded, untapping to save space..." tap.uninstall else diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 625a874210..1e69bfecdf 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -59,6 +59,8 @@ class Requirements < SimpleDelegator __getobj__.delete(req) end end + # see https://sorbet.org/docs/faq#how-can-i-fix-type-errors-that-arise-from-super + T.bind(self, T.untyped) super self end diff --git a/Library/Homebrew/dev-cmd/bump-cask-pr.rb b/Library/Homebrew/dev-cmd/bump-cask-pr.rb index 23efb2850e..71f377afda 100644 --- a/Library/Homebrew/dev-cmd/bump-cask-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-cask-pr.rb @@ -177,7 +177,7 @@ module Homebrew sig { params( cask: Cask::Cask, - new_hash: T.nilable(String), + new_hash: T.any(NilClass, String, Symbol), new_version: BumpVersionParser, replacement_pairs: T::Array[[T.any(Regexp, String), T.any(Regexp, String)]], ).returns(T::Array[[T.any(Regexp, String), T.any(Regexp, String)]]) @@ -234,7 +234,7 @@ module Homebrew end elsif new_hash opoo "Cask contains multiple hashes; only updating hash for current arch." if cask.on_system_blocks_exist? - replacement_pairs << [old_hash.to_s, new_hash] + replacement_pairs << [old_hash.to_s, new_hash.to_s] end end end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index b169d984d0..c2b5a8a933 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -126,7 +126,7 @@ class Pathname # https://bugs.ruby-lang.org/issues/7707 # In that case, use the system "mv" command. if src.symlink? - raise unless Kernel.system "mv", src, dst + raise unless Kernel.system "mv", src.to_s, dst else FileUtils.mv src, dst end diff --git a/Library/Homebrew/extend/predicable.rbi b/Library/Homebrew/extend/predicable.rbi index cd5e165e4c..027500f579 100644 --- a/Library/Homebrew/extend/predicable.rbi +++ b/Library/Homebrew/extend/predicable.rbi @@ -1,5 +1,6 @@ # typed: strict module Predicable - requires_ancestor { Class } + include Kernel + requires_ancestor { Module } end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index e7b757c5e8..631c47fbc2 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -343,7 +343,7 @@ class Formula # The path that was specified to find this formula. def specified_path - default_specified_path = Pathname(alias_path) if alias_path.present? + default_specified_path = Pathname(T.must(alias_path)) if alias_path.present? default_specified_path ||= @unresolved_path return default_specified_path if default_specified_path.presence&.exist? diff --git a/Library/Homebrew/language/node.rb b/Library/Homebrew/language/node.rb index 5974e3bc25..3e90e2fe94 100644 --- a/Library/Homebrew/language/node.rb +++ b/Library/Homebrew/language/node.rb @@ -17,7 +17,8 @@ module Language # fed to `npm install` only symlinks are created linking back to that # directory, consequently breaking that assumption. We require a tarball # because npm install creates a "real" installation when fed a tarball. - if (package = Pathname("package.json")) && package.exist? + package = Pathname("package.json") + if package.exist? begin pkg_json = JSON.parse(package.read) rescue JSON::ParserError diff --git a/Library/Homebrew/lazy_object.rb b/Library/Homebrew/lazy_object.rb index 4dfcbdb4e6..831fb9fe74 100644 --- a/Library/Homebrew/lazy_object.rb +++ b/Library/Homebrew/lazy_object.rb @@ -23,6 +23,8 @@ class LazyObject < Delegator # Forward to the inner object to make lazy objects type-checkable. def is_a?(klass) + # see https://sorbet.org/docs/faq#how-can-i-fix-type-errors-that-arise-from-super + T.bind(self, T.untyped) __getobj__.is_a?(klass) || super end end diff --git a/Library/Homebrew/macos_version.rb b/Library/Homebrew/macos_version.rb index f728b610ca..b871c3d0c7 100644 --- a/Library/Homebrew/macos_version.rb +++ b/Library/Homebrew/macos_version.rb @@ -42,7 +42,7 @@ class MacOSVersion < Version def initialize(version) raise MacOSVersion::Error, version unless /\A1\d+(?:\.\d+){0,2}\Z/.match?(version) - super(version) + super(T.must(version)) @comparison_cache = {} end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 016c80382e..4af61b3d72 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -541,11 +541,11 @@ class BottleSpecification end alias eql? == - sig { params(tag: Utils::Bottles::Tag).returns(T.any(Symbol, String)) } + sig { params(tag: Utils::Bottles::Tag).returns(String) } def tag_to_cellar(tag = Utils::Bottles.tag) spec = collector.specification_for(tag) if spec.present? - spec.cellar + spec.cellar.to_s else tag.default_cellar end diff --git a/Library/Homebrew/sorbet/parlour.rb b/Library/Homebrew/sorbet/parlour.rb index 6c64b82b53..66ca7aa820 100644 --- a/Library/Homebrew/sorbet/parlour.rb +++ b/Library/Homebrew/sorbet/parlour.rb @@ -10,7 +10,7 @@ end module Homebrew # Parlour type signature generator helper class for Homebrew. module Parlour - ROOT_DIR = T.let(Pathname(__dir__).parent.realpath.freeze, Pathname).freeze + ROOT_DIR = T.let(Pathname(T.must(__dir__)).parent.realpath.freeze, Pathname).freeze sig { returns(T::Array[Parser::AST::Node]) } def self.ast_list diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 3f6f93d61f..d52d633db8 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -132,7 +132,7 @@ module UnpackStrategy children = tmp_unpack_dir.children - if children.count == 1 && !children.first.directory? + if children.size == 1 && !children.fetch(0).directory? s = UnpackStrategy.detect(children.first, prioritize_extension: prioritize_extension) s.extract_nestedly(to: to, verbose: verbose, prioritize_extension: prioritize_extension) diff --git a/Library/Homebrew/unversioned_cask_checker.rb b/Library/Homebrew/unversioned_cask_checker.rb index fb3d02d040..842181365e 100644 --- a/Library/Homebrew/unversioned_cask_checker.rb +++ b/Library/Homebrew/unversioned_cask_checker.rb @@ -158,7 +158,7 @@ module Homebrew top_level_info_plist_paths.each(&parse_info_plist) ensure Cask::Utils.gain_permissions_remove(extract_dir) - extract_dir.mkpath + Pathname(extract_dir).mkpath end end @@ -252,7 +252,7 @@ module Homebrew }.uniq ensure Cask::Utils.gain_permissions_remove(extract_dir) - extract_dir.mkpath + Pathname(extract_dir).mkpath end end diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 1c11ecf630..a4ee5d9e7f 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -65,12 +65,14 @@ module Utils receipt_file = file_from_bottle(bottle_file, receipt_file_path) tap = Tab.from_file_content(receipt_file, "#{bottle_file}/#{receipt_file_path}").tap "#{tap}/#{name}" if tap.present? && !tap.core_tap? - elsif (bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json"))) && - bottle_json_path.exist? && + else + bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json")) + if bottle_json_path.exist? && (bottle_json_path_contents = bottle_json_path.read.presence) && (bottle_json = JSON.parse(bottle_json_path_contents).presence) && bottle_json.is_a?(Hash) - bottle_json.keys.first.presence + bottle_json.keys.first.presence + end end full_name ||= name diff --git a/Library/Homebrew/yard/templates/default/docstring/html/setup.rb b/Library/Homebrew/yard/templates/default/docstring/html/setup.rb index 27272f9ff6..860f921ef5 100644 --- a/Library/Homebrew/yard/templates/default/docstring/html/setup.rb +++ b/Library/Homebrew/yard/templates/default/docstring/html/setup.rb @@ -4,7 +4,7 @@ def init # `sorbet` is available transitively through the `yard-sorbet` plugin, but we're # outside of the standalone sorbet config, so `checked` is enabled by default - T.bind(self, YARD::Templates::Template, checked: false) + T.bind(self, T.all(Class, YARD::Templates::Template), checked: false) super return if sections.empty?