Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sorbet: Bump more files to typed: strict #17788

Merged
merged 8 commits into from
Jul 25, 2024
Merged
14 changes: 12 additions & 2 deletions Library/Homebrew/cask/info.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -25,23 +26,27 @@ def self.get_info(cask)
output
end

sig { params(cask: Cask).void }
def self.info(cask)
puts get_info(cask)

require "utils/analytics"
::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?

Expand All @@ -55,20 +60,23 @@ 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")}
#{cask.name.empty? ? Formatter.error("None") : cask.name.join("\n")}
EOS
end

sig { params(cask: Cask).returns(String) }
def self.desc_info(cask)
<<~EOS
#{ohai_title("Description")}
#{cask.desc.nil? ? Formatter.error("None") : cask.desc}
EOS
end

sig { params(cask: Cask).returns(T.nilable(String)) }
def self.language_info(cask)
return if cask.languages.empty?

Expand All @@ -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?

Expand All @@ -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|
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module Homebrew
Expand All @@ -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 " \
Expand Down Expand Up @@ -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])

issyl0 marked this conversation as resolved.
Show resolved Hide resolved
sig { params(env: Symbol, hash: T::Hash[Symbol, T.untyped]).returns(String) }
def env_method_name(env, hash)
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/official_taps.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/os.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "version"
Expand Down Expand Up @@ -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.
Expand All @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions Library/Homebrew/utils/github/actions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "securerandom"
Expand Down Expand Up @@ -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) }
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/utils/github/artifacts.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "download_strategy"
Expand All @@ -24,12 +24,14 @@

# 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)

Check warning on line 31 in Library/Homebrew/utils/github/artifacts.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/github/artifacts.rb#L30-L31

Added lines #L30 - L31 were not covered by tests
end

sig { params(timeout: T.nilable(Integer)).void }
def fetch(timeout: nil)
ohai "Downloading #{url}"
if cached_location.exist?
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/utils/tar.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "system_command"
Expand All @@ -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?

Expand All @@ -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
Expand Down