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| 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 68cdcef9abc86..58cff02330250 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 " \ @@ -481,7 +481,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::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 @@ 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. 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 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" 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) } 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? 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