diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 1806d8c190..6481b79c82 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -3,7 +3,6 @@ require "timeout" -require "utils/splat" require "utils/user" require "cask/artifact/abstract_artifact" require "cask/pkg" @@ -262,7 +261,7 @@ module Cask # learned the pid from AppleScript is already some degree of protection, # though indirect. odebug "Unix ids are #{pids.inspect} for processes with bundle identifier #{bundle_id}" - ::Utils::Splat.process_kill(signal, pids) + Process.kill(signal, *pids) sleep 3 end end diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index e06cbd1dd1..b167902f8e 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "delegate" @@ -149,7 +149,8 @@ module Homebrew if want_keg_like_cask cask_version = Cask::Cask.new(name, config: config).versions.first cask = Cask::Cask.new(name, config: config) do - version cask_version if cask_version + # This block is dynamically evaluated in `Cask::Cask#refresh`, so sorbet cannot typecheck it. + T.unsafe(self).version cask_version if cask_version end return cask end diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index cd3c98f735..568ab62d06 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "env_config" @@ -122,7 +122,9 @@ module Homebrew @args = Homebrew::CLI::Args.new # Filter out Sorbet runtime type checking method calls. - cmd_location = caller_locations.select { |location| location.path.exclude?("/gems/sorbet-runtime-") }.second + cmd_location = T.must(caller_locations).select do |location| + T.must(location.path).exclude?("/gems/sorbet-runtime-") + end.second @command_name = cmd_location.label.chomp("_args").tr("_", "-") @is_dev_cmd = cmd_location.absolute_path.start_with?(Commands::HOMEBREW_DEV_CMD_PATH) @@ -386,7 +388,7 @@ module Homebrew sig { params( - type: T.any(Symbol, T::Array[String], T::Array[Symbol]), + type: T.any(NilClass, Symbol, T::Array[String], T::Array[Symbol]), number: T.nilable(Integer), min: T.nilable(Integer), max: T.nilable(Integer), diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index 7dccca23bb..80ef49b874 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true # Contains shorthand Homebrew utility methods like `ohai`, `opoo`, `odisabled`. @@ -18,7 +18,7 @@ module Kernel def ohai_title(title) verbose = if respond_to?(:verbose?) - verbose? + T.unsafe(self).verbose? else Context.current.verbose? end @@ -34,7 +34,7 @@ module Kernel def odebug(title, *sput, always_display: false) debug = if respond_to?(:debug) - debug? + T.unsafe(self).debug? else Context.current.debug? end @@ -47,7 +47,7 @@ module Kernel def oh1_title(title, truncate: :auto) verbose = if respond_to?(:verbose?) - verbose? + T.unsafe(self).verbose? else Context.current.verbose? end @@ -361,7 +361,7 @@ module Kernel end def nostdout(&block) - if verbose? + if T.unsafe(self).verbose? yield else redirect_stdout(File::NULL, &block) @@ -436,7 +436,11 @@ module Kernel end def parse_author!(author) - /^(?[^<]+?)[ \t]*<(?[^>]+?)>$/ =~ author + match_data = /^(?[^<]+?)[ \t]*<(?[^>]+?)>$/.match(author) + if match_data + name = match_data[:name] + email = match_data[:email] + end raise UsageError, "Unable to parse name and email." if name.blank? && email.blank? { name: name, email: email } diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index df758bafeb..3ca0e63535 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "time" @@ -24,6 +24,7 @@ require "extend/kernel" module Homebrew extend Context + extend T::Sig module_function @@ -51,6 +52,7 @@ module Homebrew end # rubocop:disable Style/GlobalVars + sig { params(the_module: Module, pattern: Regexp).void } def inject_dump_stats!(the_module, pattern) @injected_dump_stat_modules ||= {} @injected_dump_stat_modules[the_module] ||= [] diff --git a/Library/Homebrew/utils/splat.rb b/Library/Homebrew/utils/splat.rb deleted file mode 100644 index e6fa62ec63..0000000000 --- a/Library/Homebrew/utils/splat.rb +++ /dev/null @@ -1,20 +0,0 @@ -# typed: false -# frozen_string_literal: true - -module Utils - # Wrappers for Ruby core methods that accept splat arguments. This file is `typed: false` by design, but allows - # other files to enable typing while making use of the wrapped methods. - # - # @api private - module Splat - extend T::Sig - - # Wrapper around `Process.kill` that accepts an array of pids. - # @see https://ruby-doc.org/3.2.1/Process.html#method-c-kill Process.kill - # @see https://github.com/sorbet/sorbet/blob/eaebdcd/rbi/core/process.rbi#L793-L800 Sorbet RBI for `Process.kill` - sig { params(signal: T.any(Integer, Symbol, String), pids: T::Array[Integer]).returns(Integer) } - def self.process_kill(signal, pids) - Process.kill(signal, *pids) - end - end -end