Enable typing in misc files

This commit is contained in:
Douglas Eichelberger 2023-02-27 11:43:16 -08:00
parent 3a02894d0b
commit d98b7845d3
6 changed files with 22 additions and 34 deletions

View File

@ -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

View File

@ -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

View File

@ -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),

View File

@ -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)
/^(?<name>[^<]+?)[ \t]*<(?<email>[^>]+?)>$/ =~ author
match_data = /^(?<name>[^<]+?)[ \t]*<(?<email>[^>]+?)>$/.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 }

View File

@ -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] ||= []

View File

@ -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