Merge pull request #17788 from Homebrew/more-sorbet-strict

sorbet: Bump more files to `typed: strict`
This commit is contained in:
Bo Anderson 2024-07-25 02:23:23 +01:00 committed by GitHub
commit d39a3a3030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 28 deletions

View File

@ -1,10 +1,11 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "json" require "json"
module Cask module Cask
class Info class Info
sig { params(cask: Cask).returns(String) }
def self.get_info(cask) def self.get_info(cask)
require "cask/installer" require "cask/installer"
@ -25,6 +26,7 @@ module Cask
output output
end end
sig { params(cask: Cask).void }
def self.info(cask) def self.info(cask)
puts get_info(cask) puts get_info(cask)
@ -32,16 +34,19 @@ module Cask
::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new) ::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
end end
sig { params(cask: Cask).returns(String) }
def self.title_info(cask) def self.title_info(cask)
title = "#{oh1_title(cask.token)}: #{cask.version}" title = "#{oh1_title(cask.token)}: #{cask.version}"
title += " (auto_updates)" if cask.auto_updates title += " (auto_updates)" if cask.auto_updates
title title
end end
sig { params(cask: Cask).returns(String) }
def self.installation_info(cask) def self.installation_info(cask)
return "Not installed" unless cask.installed? return "Not installed" unless cask.installed?
return "No installed version" unless (installed_version = cask.installed_version).present?
versioned_staged_path = cask.caskroom_path.join(cask.installed_version) versioned_staged_path = cask.caskroom_path.join(installed_version)
return "Installed\n#{versioned_staged_path} (#{Formatter.error("does not exist")})\n" unless versioned_staged_path.exist? return "Installed\n#{versioned_staged_path} (#{Formatter.error("does not exist")})\n" unless versioned_staged_path.exist?
@ -55,6 +60,7 @@ module Cask
info.join("\n") info.join("\n")
end end
sig { params(cask: Cask).returns(String) }
def self.name_info(cask) def self.name_info(cask)
<<~EOS <<~EOS
#{ohai_title((cask.name.size > 1) ? "Names" : "Name")} #{ohai_title((cask.name.size > 1) ? "Names" : "Name")}
@ -62,6 +68,7 @@ module Cask
EOS EOS
end end
sig { params(cask: Cask).returns(String) }
def self.desc_info(cask) def self.desc_info(cask)
<<~EOS <<~EOS
#{ohai_title("Description")} #{ohai_title("Description")}
@ -69,6 +76,7 @@ module Cask
EOS EOS
end end
sig { params(cask: Cask).returns(T.nilable(String)) }
def self.language_info(cask) def self.language_info(cask)
return if cask.languages.empty? return if cask.languages.empty?
@ -78,6 +86,7 @@ module Cask
EOS EOS
end end
sig { params(cask: Cask).returns(T.nilable(String)) }
def self.repo_info(cask) def self.repo_info(cask)
return if cask.tap.nil? return if cask.tap.nil?
@ -90,6 +99,7 @@ module Cask
"From: #{Formatter.url(url)}" "From: #{Formatter.url(url)}"
end end
sig { params(cask: Cask).returns(String) }
def self.artifact_info(cask) def self.artifact_info(cask)
artifact_output = ohai_title("Artifacts").dup artifact_output = ohai_title("Artifacts").dup
cask.artifacts.each do |artifact| cask.artifacts.each do |artifact|

View File

@ -8,7 +8,7 @@ module Homebrew
module Cmd module Cmd
class CleanupCmd < AbstractCommand class CleanupCmd < AbstractCommand
cmd_args do cmd_args do
days = Homebrew::EnvConfig::ENVS[:HOMEBREW_CLEANUP_MAX_AGE_DAYS][:default] days = Homebrew::EnvConfig::ENVS[:HOMEBREW_CLEANUP_MAX_AGE_DAYS]&.dig(:default)
description <<~EOS description <<~EOS
Remove stale lock files and outdated downloads for all formulae and casks, Remove stale lock files and outdated downloads for all formulae and casks,
and remove old versions of installed formulae. If arguments are specified, and remove old versions of installed formulae. If arguments are specified,

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
@ -8,7 +8,7 @@ module Homebrew
module EnvConfig module EnvConfig
module_function module_function
ENVS = { ENVS = T.let({
HOMEBREW_ALLOWED_TAPS: { HOMEBREW_ALLOWED_TAPS: {
description: "A space-separated list of taps. Homebrew will refuse to install a " \ description: "A space-separated list of taps. Homebrew will refuse to install a " \
"formula unless it and all of its dependencies are in an official tap " \ "formula unless it and all of its dependencies are in an official tap " \
@ -481,7 +481,7 @@ module Homebrew
description: "A comma-separated list of hostnames and domain names excluded " \ description: "A comma-separated list of hostnames and domain names excluded " \
"from proxying by `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.", "from proxying by `curl`(1), `git`(1) and `svn`(1) when downloading through Homebrew.",
}, },
}.freeze }.freeze, T::Hash[Symbol, T::Hash[Symbol, T.untyped]])
sig { params(env: Symbol, hash: T::Hash[Symbol, T.untyped]).returns(String) } sig { params(env: Symbol, hash: T::Hash[Symbol, T.untyped]).returns(String) }
def env_method_name(env, hash) def env_method_name(env, hash)
@ -492,10 +492,10 @@ module Homebrew
method_name method_name
end end
CUSTOM_IMPLEMENTATIONS = Set.new([ CUSTOM_IMPLEMENTATIONS = T.let(Set.new([
:HOMEBREW_MAKE_JOBS, :HOMEBREW_MAKE_JOBS,
:HOMEBREW_CASK_OPTS, :HOMEBREW_CASK_OPTS,
]).freeze ]).freeze, T::Set[Symbol])
ENVS.each do |env, hash| ENVS.each do |env, hash|
# Needs a custom implementation. # Needs a custom implementation.

View File

@ -1,17 +1,17 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
OFFICIAL_CASK_TAPS = %w[ OFFICIAL_CASK_TAPS = %w[
cask cask
].freeze ].freeze
OFFICIAL_CMD_TAPS = { OFFICIAL_CMD_TAPS = T.let({
"homebrew/aliases" => ["alias", "unalias"], "homebrew/aliases" => ["alias", "unalias"],
"homebrew/bundle" => ["bundle"], "homebrew/bundle" => ["bundle"],
"homebrew/command-not-found" => ["command-not-found-init", "which-formula", "which-update"], "homebrew/command-not-found" => ["command-not-found-init", "which-formula", "which-update"],
"homebrew/test-bot" => ["test-bot"], "homebrew/test-bot" => ["test-bot"],
"homebrew/services" => ["services"], "homebrew/services" => ["services"],
}.freeze }.freeze, T::Hash[String, T::Array[String]])
DEPRECATED_OFFICIAL_TAPS = %w[ DEPRECATED_OFFICIAL_TAPS = %w[
apache apache

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "version" require "version"
@ -31,7 +31,7 @@ module OS
sig { returns(Version) } sig { returns(Version) }
def self.kernel_version def self.kernel_version
require "utils/popen" require "utils/popen"
@kernel_version ||= Version.new(Utils.safe_popen_read("uname", "-r").chomp) @kernel_version ||= T.let(Version.new(Utils.safe_popen_read("uname", "-r").chomp), T.nilable(Version))
end end
# Get the kernel name. # Get the kernel name.
@ -40,10 +40,10 @@ module OS
sig { returns(String) } sig { returns(String) }
def self.kernel_name def self.kernel_name
require "utils/popen" require "utils/popen"
@kernel_name ||= Utils.safe_popen_read("uname", "-s").chomp @kernel_name ||= T.let(Utils.safe_popen_read("uname", "-s").chomp, T.nilable(String))
end end
::OS_VERSION = ENV.fetch("HOMEBREW_OS_VERSION").freeze ::OS_VERSION = T.let(ENV.fetch("HOMEBREW_OS_VERSION").freeze, String)
# See Linux-CI.md # See Linux-CI.md
LINUX_CI_OS_VERSION = "Ubuntu 22.04" LINUX_CI_OS_VERSION = "Ubuntu 22.04"

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "securerandom" require "securerandom"
@ -85,13 +85,13 @@ module GitHub
raise ArgumentError, "Unsupported type: #{type.inspect}" if ANNOTATION_TYPES.exclude?(type) raise ArgumentError, "Unsupported type: #{type.inspect}" if ANNOTATION_TYPES.exclude?(type)
@type = type @type = type
@message = Tty.strip_ansi(message) @message = T.let(Tty.strip_ansi(message), String)
@file = self.class.path_relative_to_workspace(file) if file.present? @file = T.let(self.class.path_relative_to_workspace(file), T.nilable(Pathname)) if file.present?
@title = Tty.strip_ansi(title) if title @title = T.let(Tty.strip_ansi(title), String) if title
@line = Integer(line) if line @line = T.let(Integer(line), Integer) if line
@end_line = Integer(end_line) if end_line @end_line = T.let(Integer(end_line), Integer) if end_line
@column = Integer(column) if column @column = T.let(Integer(column), Integer) if column
@end_column = Integer(end_column) if end_column @end_column = T.let(Integer(end_column), Integer) if end_column
end end
sig { returns(String) } sig { returns(String) }

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "download_strategy" require "download_strategy"
@ -24,12 +24,14 @@ end
# Strategy for downloading an artifact from GitHub Actions. # Strategy for downloading an artifact from GitHub Actions.
class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy class GitHubArtifactDownloadStrategy < AbstractFileDownloadStrategy
sig { params(url: String, artifact_id: String, token: String).void }
def initialize(url, artifact_id, token:) def initialize(url, artifact_id, token:)
super(url, "artifact", artifact_id) super(url, "artifact", artifact_id)
@cache = HOMEBREW_CACHE/"gh-actions-artifact" @cache = T.let(HOMEBREW_CACHE/"gh-actions-artifact", Pathname)
@token = token @token = T.let(token, String)
end end
sig { params(timeout: T.nilable(Integer)).void }
def fetch(timeout: nil) def fetch(timeout: nil)
ohai "Downloading #{url}" ohai "Downloading #{url}"
if cached_location.exist? if cached_location.exist?

View File

@ -1,4 +1,4 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "system_command" require "system_command"
@ -11,18 +11,21 @@ module Utils
TAR_FILE_EXTENSIONS = %w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ].freeze TAR_FILE_EXTENSIONS = %w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ].freeze
sig { returns(T::Boolean) }
def available? def available?
executable.present? executable.present?
end end
sig { returns(T.nilable(Pathname)) }
def executable def executable
return @executable if defined?(@executable) return @executable if defined?(@executable)
gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
@executable = which("gtar") || gnu_tar_gtar || which("tar") @executable = T.let((which("gtar") || gnu_tar_gtar || which("tar")), T.nilable(Pathname))
end end
sig { params(path: T.any(Pathname, String)).void }
def validate_file(path) def validate_file(path)
return unless available? return unless available?
@ -33,6 +36,7 @@ module Utils
odie "#{path} is not a valid tar file!" if !status.success? || stdout.blank? odie "#{path} is not a valid tar file!" if !status.success? || stdout.blank?
end end
sig { void }
def clear_executable_cache def clear_executable_cache
remove_instance_variable(:@executable) if defined?(@executable) remove_instance_variable(:@executable) if defined?(@executable)
end end