Merge pull request #18354 from Homebrew/back-to-srb

Bump more files to Sorbet `typed: strict`
This commit is contained in:
Issy Long 2024-10-06 21:01:21 +01:00 committed by GitHub
commit a917ce2971
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 10 deletions

View File

@ -144,7 +144,7 @@ begin
end end
rescue UsageError => e rescue UsageError => e
require "help" 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 rescue SystemExit => e
onoe "Kernel.exit" if args&.debug? && !e.success? onoe "Kernel.exit" if args&.debug? && !e.success?
if args&.debug? || ARGV.include?("--debug") if args&.debug? || ARGV.include?("--debug")

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "cask/cask_loader" require "cask/cask_loader"
@ -6,6 +6,7 @@ require "utils/inreplace"
module Cask module Cask
class Migrator class Migrator
sig { returns(Cask) }
attr_reader :old_cask, :new_cask attr_reader :old_cask, :new_cask
sig { params(old_cask: Cask, new_cask: Cask).void } sig { params(old_cask: Cask, new_cask: Cask).void }
@ -38,7 +39,10 @@ module Cask
old_caskroom_path = old_cask.caskroom_path old_caskroom_path = old_cask.caskroom_path
new_caskroom_path = new_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
return if old_caskfile.nil?
old_installed_caskfile = old_caskfile.relative_path_from(old_caskroom_path)
new_installed_caskfile = old_installed_caskfile.dirname/old_installed_caskfile.basename.sub( new_installed_caskfile = old_installed_caskfile.dirname/old_installed_caskfile.basename.sub(
old_token, old_token,
new_token, new_token,

View File

@ -39,6 +39,11 @@ class Dependencies < SimpleDelegator
def inspect def inspect
"#<#{self.class.name}: #{__getobj__}>" "#<#{self.class.name}: #{__getobj__}>"
end end
sig { returns(T::Array[Dependency]) }
def to_a
__getobj__.to_a
end
end end
# A collection of requirements. # A collection of requirements.

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "utils/shell" require "utils/shell"
@ -191,6 +191,7 @@ module FormulaCellarChecks
EOS EOS
end end
sig { params(lib: Pathname, deps: Dependencies).returns(T.nilable(String)) }
def check_python_packages(lib, deps) def check_python_packages(lib, deps)
return unless lib.directory? return unless lib.directory?
@ -208,7 +209,8 @@ module FormulaCellarChecks
return if pythons.blank? return if pythons.blank?
python_deps = deps.map(&:name) python_deps = deps.to_a
.map(&:name)
.grep(/^python(@.*)?$/) .grep(/^python(@.*)?$/)
.filter_map { |d| Formula[d].version.to_s[/^\d+\.\d+/] } .filter_map { |d| Formula[d].version.to_s[/^\d+\.\d+/] }
@ -250,6 +252,7 @@ module FormulaCellarChecks
EOS EOS
end end
sig { params(prefix: Pathname, plist: Pathname).returns(T.nilable(String)) }
def check_plist(prefix, plist) def check_plist(prefix, plist)
return unless prefix.directory? return unless prefix.directory?
@ -412,7 +415,7 @@ module FormulaCellarChecks
sig { void } sig { void }
def audit_installed def audit_installed
@new_formula ||= false @new_formula ||= T.let(false, T.nilable(T::Boolean))
problem_if_output(check_manpages) problem_if_output(check_manpages)
problem_if_output(check_infopages) problem_if_output(check_infopages)
@ -442,8 +445,9 @@ module FormulaCellarChecks
File.directory?(dir) ? Dir.chdir(dir) { Dir[pattern] } : [] File.directory?(dir) ? Dir.chdir(dir) { Dir[pattern] } : []
end end
def cpuid_instruction?(file, objdump = "objdump") sig { params(file: T.any(Pathname, String), objdump: Pathname).returns(T::Boolean) }
@instruction_column_index ||= {} def cpuid_instruction?(file, objdump)
@instruction_column_index ||= T.let({}, T.nilable(T::Hash[Pathname, Integer]))
@instruction_column_index[objdump] ||= begin @instruction_column_index[objdump] ||= begin
objdump_version = Utils.popen_read(objdump, "--version") objdump_version = Utils.popen_read(objdump, "--version")

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "cli/parser" require "cli/parser"
@ -7,6 +7,14 @@ require "commands"
module Homebrew module Homebrew
# Helper module for printing help output. # Helper module for printing help output.
module Help 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: []) def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
if cmd.nil? if cmd.nil?
# Handle `brew` (no arguments). # Handle `brew` (no arguments).
@ -39,6 +47,13 @@ module Homebrew
exit 0 exit 0
end end
sig {
params(
cmd: String,
path: Pathname,
remaining_args: T::Array[String],
).returns(String)
}
def self.command_help(cmd, path, remaining_args:) def self.command_help(cmd, path, remaining_args:)
# Only some types of commands can have a parser. # Only some types of commands can have a parser.
output = if Commands.valid_internal_cmd?(cmd) || output = if Commands.valid_internal_cmd?(cmd) ||
@ -58,6 +73,12 @@ module Homebrew
end end
private_class_method :command_help 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:) def self.parser_help(path, remaining_args:)
# Let OptionParser generate help text for commands which have a parser. # Let OptionParser generate help text for commands which have a parser.
cmd_parser = CLI::Parser.from_cmd_path(path) cmd_parser = CLI::Parser.from_cmd_path(path)
@ -69,14 +90,16 @@ module Homebrew
end end
private_class_method :parser_help private_class_method :parser_help
sig { params(path: Pathname).returns(T::Array[String]) }
def self.command_help_lines(path) def self.command_help_lines(path)
path.read path.read
.lines .lines
.grep(/^#:/) .grep(/^#:/)
.map { |line| line.slice(2..-1).delete_prefix(" ") } .filter_map { |line| line.slice(2..-1)&.delete_prefix(" ") }
end end
private_class_method :command_help_lines private_class_method :command_help_lines
sig { params(path: Pathname).returns(T.nilable(String)) }
def self.comment_help(path) def self.comment_help(path)
# Otherwise read #: lines from the file. # Otherwise read #: lines from the file.
help_lines = command_help_lines(path) help_lines = command_help_lines(path)