From 7282b4d7a295fad91346e20cc7a7913b3b2a7841 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Fri, 12 Jul 2024 14:24:03 -0400 Subject: [PATCH 1/8] os: Bump to Sorbet `typed: strict` --- Library/Homebrew/os.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/os.rb b/Library/Homebrew/os.rb index 6dfeeb460faec..a22add846fd4a 100644 --- a/Library/Homebrew/os.rb +++ b/Library/Homebrew/os.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "version" @@ -31,7 +31,7 @@ def self.linux? 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 @@ def self.kernel_version 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" From 75b72f2fd9701d278ff8946d1c62191b1e03085f Mon Sep 17 00:00:00 2001 From: Issy Long Date: Mon, 15 Jul 2024 23:22:31 -0400 Subject: [PATCH 2/8] official_taps: Bump to Sorbet `typed: strict` --- Library/Homebrew/official_taps.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/official_taps.rb b/Library/Homebrew/official_taps.rb index 510c89ad23378..65c0473342280 100644 --- a/Library/Homebrew/official_taps.rb +++ b/Library/Homebrew/official_taps.rb @@ -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 From 3290b7e61627a5b78b8ed416154b283ba1873636 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 16 Jul 2024 17:58:15 -0400 Subject: [PATCH 3/8] env_config: Bump to Sorbet `typed: strict` --- Library/Homebrew/env_config.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 35b56c45eec87..b05296e6ebb4e 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -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 " \ @@ -477,7 +477,7 @@ module EnvConfig 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.untyped]) sig { params(env: Symbol, hash: T::Hash[Symbol, T.untyped]).returns(String) } def env_method_name(env, hash) @@ -488,10 +488,10 @@ def env_method_name(env, hash) 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. From 5b84ee0195d3c01e8c086754cc14511480f66519 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 16 Jul 2024 18:11:15 -0400 Subject: [PATCH 4/8] utils/tar: Bump to Sorbet `typed: strict` --- Library/Homebrew/utils/tar.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils/tar.rb b/Library/Homebrew/utils/tar.rb index bf4df5e664943..dd1dca89dcce4 100644 --- a/Library/Homebrew/utils/tar.rb +++ b/Library/Homebrew/utils/tar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -11,18 +11,21 @@ class << self 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 @@ def validate_file(path) 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 From 07f9f3f8e06f34c0f37d63097965c9c835abb121 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Wed, 17 Jul 2024 16:19:12 -0400 Subject: [PATCH 5/8] utils/github/artifacts: Bump to Sorbet `typed: strict` --- Library/Homebrew/utils/github/artifacts.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/github/artifacts.rb b/Library/Homebrew/utils/github/artifacts.rb index 9e0756a5f1a8f..607ee521f9bc6 100644 --- a/Library/Homebrew/utils/github/artifacts.rb +++ b/Library/Homebrew/utils/github/artifacts.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "download_strategy" @@ -24,12 +24,14 @@ def self.download_artifact(url, artifact_id) # 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? From b0331195235b906f7c7175b91d11c067ab9cb8af Mon Sep 17 00:00:00 2001 From: Issy Long Date: Wed, 17 Jul 2024 16:21:41 -0400 Subject: [PATCH 6/8] utils/github/actions: Bump to Sorbet `typed: strict` --- Library/Homebrew/utils/github/actions.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/utils/github/actions.rb b/Library/Homebrew/utils/github/actions.rb index 3d6e57cc47db1..9be540dc58b28 100644 --- a/Library/Homebrew/utils/github/actions.rb +++ b/Library/Homebrew/utils/github/actions.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "securerandom" @@ -85,13 +85,13 @@ def initialize(type, message, file: nil, title: nil, line: nil, end_line: nil, c 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) } From fdb661e2b972d57a59264860443766c62456dd38 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Wed, 17 Jul 2024 16:57:34 -0400 Subject: [PATCH 7/8] cask/info: Bump to Sorbet `typed: strict` --- Library/Homebrew/cask/info.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/info.rb b/Library/Homebrew/cask/info.rb index acac2cbc29096..937d620c922be 100644 --- a/Library/Homebrew/cask/info.rb +++ b/Library/Homebrew/cask/info.rb @@ -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 @@ def self.get_info(cask) output end + sig { params(cask: Cask).void } def self.info(cask) puts get_info(cask) @@ -32,16 +34,19 @@ def self.info(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 @@ def self.installation_info(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 @@ def self.name_info(cask) EOS end + sig { params(cask: Cask).returns(String) } def self.desc_info(cask) <<~EOS #{ohai_title("Description")} @@ -69,6 +76,7 @@ def self.desc_info(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 @@ def self.language_info(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 @@ def self.repo_info(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| From 6ad0ebd5b443f7694f5d6ab69d8e4f6ba913ff28 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 23 Jul 2024 11:26:12 +0100 Subject: [PATCH 8/8] env_config: Tighten hash types some more Co-authored-by: Bo Anderson --- Library/Homebrew/cmd/cleanup.rb | 2 +- Library/Homebrew/env_config.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 4430137479c72..4d75cfaa5ee34 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -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, diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index b05296e6ebb4e..ce228ec5303fd 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -477,7 +477,7 @@ module EnvConfig 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, T::Hash[Symbol, T.untyped]) + }.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)