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

Bump more files to Sorbet typed: strict #18354

Merged
merged 2 commits into from
Oct 6, 2024
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/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
end
rescue UsageError => e
require "help"
Homebrew::Help.help cmd, remaining_args: args&.remaining, usage_error: e.message
Homebrew::Help.help cmd, remaining_args: args&.remaining || [], usage_error: e.message
rescue SystemExit => e
onoe "Kernel.exit" if args&.debug? && !e.success?
if args&.debug? || ARGV.include?("--debug")
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/cask/migrator.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "cask/cask_loader"
require "utils/inreplace"

module Cask
class Migrator
sig { returns(Cask) }
attr_reader :old_cask, :new_cask

sig { params(old_cask: Cask, new_cask: Cask).void }
Expand Down Expand Up @@ -38,7 +39,10 @@
old_caskroom_path = old_cask.caskroom_path
new_caskroom_path = new_cask.caskroom_path

old_installed_caskfile = old_cask.installed_caskfile.relative_path_from(old_caskroom_path)
old_caskfile = old_cask.installed_caskfile

Check warning on line 42 in Library/Homebrew/cask/migrator.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/migrator.rb#L42

Added line #L42 was not covered by tests
return if old_caskfile.nil?

old_installed_caskfile = old_caskfile.relative_path_from(old_caskroom_path)

Check warning on line 45 in Library/Homebrew/cask/migrator.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/migrator.rb#L45

Added line #L45 was not covered by tests
new_installed_caskfile = old_installed_caskfile.dirname/old_installed_caskfile.basename.sub(
old_token,
new_token,
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def dup_without_system_deps
def inspect
"#<#{self.class.name}: #{__getobj__}>"
end

sig { returns(T::Array[Dependency]) }
def to_a
__getobj__.to_a
end
end

# A collection of requirements.
Expand Down
14 changes: 9 additions & 5 deletions Library/Homebrew/formula_cellar_checks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "utils/shell"
Expand Down Expand Up @@ -191,6 +191,7 @@
EOS
end

sig { params(lib: Pathname, deps: Dependencies).returns(T.nilable(String)) }
def check_python_packages(lib, deps)
return unless lib.directory?

Expand All @@ -208,7 +209,8 @@

return if pythons.blank?

python_deps = deps.map(&:name)
python_deps = deps.to_a

Check warning on line 212 in Library/Homebrew/formula_cellar_checks.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_cellar_checks.rb#L212

Added line #L212 was not covered by tests
.map(&:name)
.grep(/^python(@.*)?$/)
.filter_map { |d| Formula[d].version.to_s[/^\d+\.\d+/] }

Expand Down Expand Up @@ -250,6 +252,7 @@
EOS
end

sig { params(prefix: Pathname, plist: Pathname).returns(T.nilable(String)) }
def check_plist(prefix, plist)
return unless prefix.directory?

Expand Down Expand Up @@ -412,7 +415,7 @@

sig { void }
def audit_installed
@new_formula ||= false
@new_formula ||= T.let(false, T.nilable(T::Boolean))

problem_if_output(check_manpages)
problem_if_output(check_infopages)
Expand Down Expand Up @@ -442,8 +445,9 @@
File.directory?(dir) ? Dir.chdir(dir) { Dir[pattern] } : []
end

def cpuid_instruction?(file, objdump = "objdump")
@instruction_column_index ||= {}
sig { params(file: T.any(Pathname, String), objdump: Pathname).returns(T::Boolean) }
def cpuid_instruction?(file, objdump)
@instruction_column_index ||= T.let({}, T.nilable(T::Hash[Pathname, Integer]))

Check warning on line 450 in Library/Homebrew/formula_cellar_checks.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_cellar_checks.rb#L450

Added line #L450 was not covered by tests
@instruction_column_index[objdump] ||= begin
objdump_version = Utils.popen_read(objdump, "--version")

Expand Down
27 changes: 25 additions & 2 deletions Library/Homebrew/help.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "cli/parser"
Expand All @@ -7,6 +7,14 @@
module Homebrew
# Helper module for printing help output.
module Help
sig {
params(
cmd: T.nilable(String),
empty_argv: T::Boolean,
usage_error: T.nilable(String),
remaining_args: T::Array[String],
).void
}
def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
if cmd.nil?
# Handle `brew` (no arguments).
Expand Down Expand Up @@ -39,6 +47,13 @@ def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: []
exit 0
end

sig {
params(
cmd: String,
path: Pathname,
remaining_args: T::Array[String],
).returns(String)
}
def self.command_help(cmd, path, remaining_args:)
# Only some types of commands can have a parser.
output = if Commands.valid_internal_cmd?(cmd) ||
Expand All @@ -58,6 +73,12 @@ def self.command_help(cmd, path, remaining_args:)
end
private_class_method :command_help

sig {
params(
path: Pathname,
remaining_args: T::Array[String],
).returns(T.nilable(String))
}
def self.parser_help(path, remaining_args:)
# Let OptionParser generate help text for commands which have a parser.
cmd_parser = CLI::Parser.from_cmd_path(path)
Expand All @@ -69,14 +90,16 @@ def self.parser_help(path, remaining_args:)
end
private_class_method :parser_help

sig { params(path: Pathname).returns(T::Array[String]) }
def self.command_help_lines(path)
path.read
.lines
.grep(/^#:/)
.map { |line| line.slice(2..-1).delete_prefix(" ") }
.filter_map { |line| line.slice(2..-1)&.delete_prefix(" ") }
end
private_class_method :command_help_lines

sig { params(path: Pathname).returns(T.nilable(String)) }
def self.comment_help(path)
# Otherwise read #: lines from the file.
help_lines = command_help_lines(path)
Expand Down
Loading