Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorbet updates for compatibility with recent releases #16183

Merged
merged 8 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/relocated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.from_args(cask, *args)
source_string, target_hash = args

if target_hash
raise CaskInvalidError unless target_hash.respond_to?(:keys)
raise CaskInvalidError, cask unless target_hash.respond_to?(:keys)

target_hash.assert_valid_keys(:target)
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def self.canonicalize(config)
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]
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def location
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
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)

Check warning on line 323 in Library/Homebrew/cmd/update-report.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/update-report.rb#L323

Added line #L323 was not covered by tests
ohai "#{tap.name} is old and unneeded, untapping to save space..."
tap.uninstall
else
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def <<(other)
__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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bump-cask-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
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)]])
Expand Down Expand Up @@ -234,7 +234,7 @@
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]

Check warning on line 237 in Library/Homebrew/dev-cmd/bump-cask-pr.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bump-cask-pr.rb#L237

Added line #L237 was not covered by tests
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def install_p(src, new_basename)
# 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
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/extend/predicable.rbi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# typed: strict

module Predicable
requires_ancestor { Class }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is disallowed as of sorbet/sorbet#6983

include Kernel
requires_ancestor { Module }
end
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def full_installed_alias_name

# 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?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def pour_bottle?(output_warning: false)

unless bottle.compatible_locations?
if output_warning
prefix = Pathname(bottle.cellar).parent
prefix = Pathname(bottle.cellar.to_s).parent
opoo <<~EOS
Building #{formula.full_name} from source as the bottle needs:
- HOMEBREW_CELLAR: #{bottle.cellar} (yours is #{HOMEBREW_CELLAR})
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/language/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def self.pack_for_installation
# 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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/lazy_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __setobj__(callable)

# 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
2 changes: 1 addition & 1 deletion Library/Homebrew/macos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.from_symbol(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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def compatible_locations?(tag: Utils::Bottles.tag)

return true if RELOCATABLE_CELLARS.include?(cellar)

prefix = Pathname(cellar).parent.to_s
prefix = Pathname(cellar.to_s).parent.to_s

cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/sorbet/parlour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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

Check warning on line 13 in Library/Homebrew/sorbet/parlour.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/sorbet/parlour.rb#L13

Added line #L13 was not covered by tests

sig { returns(T::Array[Parser::AST::Node]) }
def self.ast_list
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio

children = tmp_unpack_dir.children

if children.count == 1 && !children.first.directory?
if children.size == 1 && !children.fetch(0).directory?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of size here is a minor, unrelated performance fix

s = UnpackStrategy.detect(children.first, prioritize_extension: prioritize_extension)

s.extract_nestedly(to: to, verbose: verbose, prioritize_extension: prioritize_extension)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/unversioned_cask_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
top_level_info_plist_paths.each(&parse_info_plist)
ensure
Cask::Utils.gain_permissions_remove(extract_dir)
extract_dir.mkpath
Pathname(extract_dir).mkpath

Check warning on line 161 in Library/Homebrew/unversioned_cask_checker.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unversioned_cask_checker.rb#L161

Added line #L161 was not covered by tests
end
end

Expand Down Expand Up @@ -252,7 +252,7 @@
}.uniq
ensure
Cask::Utils.gain_permissions_remove(extract_dir)
extract_dir.mkpath
Pathname(extract_dir).mkpath

Check warning on line 255 in Library/Homebrew/unversioned_cask_checker.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unversioned_cask_checker.rb#L255

Added line #L255 was not covered by tests
end
end

Expand Down
14 changes: 8 additions & 6 deletions Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@
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? &&
(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
else
bottle_json_path = Pathname(bottle_file.sub(/\.(\d+\.)?tar\.gz$/, ".json"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always true assignments in conditionals seem to be disallowed now: sorbet/sorbet#7463

(It's probably worth the reviewer's attention to check that the branching logic is unchanged.)

if bottle_json_path.exist? &&
(bottle_json_path_contents = bottle_json_path.read.presence) &&
(bottle_json = JSON.parse(bottle_json_path_contents).presence) &&

Check warning on line 72 in Library/Homebrew/utils/bottles.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/bottles.rb#L71-L72

Added lines #L71 - L72 were not covered by tests
bottle_json.is_a?(Hash)
bottle_json.keys.first.presence
end
end
full_name ||= name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 7 in Library/Homebrew/yard/templates/default/docstring/html/setup.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/yard/templates/default/docstring/html/setup.rb#L7

Added line #L7 was not covered by tests
super

return if sections.empty?
Expand Down