resolve typecheck errors

This commit is contained in:
Douglas Eichelberger 2023-11-05 08:55:58 -08:00
parent 61691aa48a
commit 0191af7899
18 changed files with 30 additions and 20 deletions

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,6 @@
# typed: strict
module Predicable
requires_ancestor { Class }
include Kernel
requires_ancestor { Module }
end

View File

@ -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?

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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?