From 404666b60e734ca876a86bf7e11f52b8505da150 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Wed, 18 Sep 2024 20:39:57 +0000 Subject: [PATCH] Bump more files to Sorbet `typed: strict` --- Library/Homebrew/cask/migrator.rb | 7 ++++-- Library/Homebrew/formula_cellar_checks.rb | 9 +++++--- Library/Homebrew/help.rb | 28 +++++++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/migrator.rb b/Library/Homebrew/cask/migrator.rb index 9f15da316cf0a..01ba2ec902873 100644 --- a/Library/Homebrew/cask/migrator.rb +++ b/Library/Homebrew/cask/migrator.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "cask/cask_loader" @@ -6,6 +6,7 @@ module Cask class Migrator + sig { returns(Cask) } attr_reader :old_cask, :new_cask sig { params(old_cask: Cask, new_cask: Cask).void } @@ -38,7 +39,9 @@ def migrate(dry_run: false) 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) + return if (old_caskfile = old_cask.installed_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( old_token, new_token, diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 45973181e7631..6f16886611769 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "utils/shell" @@ -191,6 +191,7 @@ def check_elisp_root(share, name) EOS end + sig { params(lib: Pathname, deps: T::Array[Formula]).returns(T.nilable(String)) } def check_python_packages(lib, deps) return unless lib.directory? @@ -250,6 +251,7 @@ def check_shim_references(prefix) EOS end + sig { params(prefix: Pathname, plist: Pathname).returns(T.nilable(String)) } def check_plist(prefix, plist) return unless prefix.directory? @@ -412,7 +414,7 @@ def check_binary_arches(formula) 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) @@ -442,8 +444,9 @@ def relative_glob(dir, pattern) File.directory?(dir) ? Dir.chdir(dir) { Dir[pattern] } : [] end + sig { params(file: T.any(Pathname, String), objdump: String).returns(T::Boolean) } def cpuid_instruction?(file, objdump = "objdump") - @instruction_column_index ||= {} + @instruction_column_index ||= T.let({}, T.nilable(T::Hash[String, T.untyped])) @instruction_column_index[objdump] ||= begin objdump_version = Utils.popen_read(objdump, "--version") diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index 88b6e297baeb2..2ac8c6790d8c9 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "cli/parser" @@ -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.nilable(T::Array[String]) + ).void + } def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: []) if cmd.nil? # Handle `brew` (no arguments). @@ -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.nilable(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) || @@ -58,10 +73,17 @@ def self.command_help(cmd, path, remaining_args:) end private_class_method :command_help + sig { + params( + path: Pathname, + remaining_args: T.nilable(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) return unless cmd_parser + return unless remaining_args # Try parsing arguments here in order to show formula options in help output. cmd_parser.parse(remaining_args, ignore_invalid_options: true) @@ -69,14 +91,16 @@ def self.parser_help(path, remaining_args:) end private_class_method :parser_help + sig { params(path: Pathname).returns(T::Array[T.nilable(String)]) } def self.command_help_lines(path) path.read .lines .grep(/^#:/) - .map { |line| line.slice(2..-1).delete_prefix(" ") } + .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)