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

View File

@ -8,7 +8,7 @@ module Homebrew
module Cmd
class CleanupCmd < AbstractCommand
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
Remove stale lock files and outdated downloads for all formulae and casks,
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
module Homebrew
@ -8,7 +8,7 @@ module Homebrew
module EnvConfig
module_function
ENVS = {
ENVS = T.let({
HOMEBREW_ALLOWED_TAPS: {
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 " \
@ -481,7 +481,7 @@ module Homebrew
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.",
},
}.freeze
}.freeze, T::Hash[Symbol, T::Hash[Symbol, T.untyped]])
sig { params(env: Symbol, hash: T::Hash[Symbol, T.untyped]).returns(String) }
def env_method_name(env, hash)
@ -492,10 +492,10 @@ module Homebrew
method_name
end
CUSTOM_IMPLEMENTATIONS = Set.new([
CUSTOM_IMPLEMENTATIONS = T.let(Set.new([
:HOMEBREW_MAKE_JOBS,
:HOMEBREW_CASK_OPTS,
]).freeze
]).freeze, T::Set[Symbol])
ENVS.each do |env, hash|
# Needs a custom implementation.

View File

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

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "version"
@ -31,7 +31,7 @@ module OS
sig { returns(Version) }
def self.kernel_version
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
# Get the kernel name.
@ -40,10 +40,10 @@ module OS
sig { returns(String) }
def self.kernel_name
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
::OS_VERSION = ENV.fetch("HOMEBREW_OS_VERSION").freeze
::OS_VERSION = T.let(ENV.fetch("HOMEBREW_OS_VERSION").freeze, String)
# See Linux-CI.md
LINUX_CI_OS_VERSION = "Ubuntu 22.04"

View File

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

View File

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

View File

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