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

Merged
merged 13 commits into from
Aug 12, 2024
Merged
14 changes: 7 additions & 7 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def cask_plist_min_os
def audit_github_prerelease_version
odebug "Auditing GitHub prerelease"
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online?
return if user.nil?
return if user.nil? || repo.nil?
carlocab marked this conversation as resolved.
Show resolved Hide resolved

tag = SharedAudits.github_tag_from_url(cask.url)
tag ||= cask.version
Expand All @@ -765,7 +765,7 @@ def audit_github_prerelease_version
sig { void }
def audit_gitlab_prerelease_version
user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online?
return if user.nil?
return if user.nil? || repo.nil?

odebug "Auditing GitLab prerelease"

Expand All @@ -781,7 +781,7 @@ def audit_github_repository_archived
return if cask.deprecated? || cask.disabled?

user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online?
return if user.nil?
return if user.nil? || repo.nil?

metadata = SharedAudits.github_repo_data(user, repo)
return if metadata.nil?
Expand All @@ -795,7 +795,7 @@ def audit_gitlab_repository_archived
return if cask.deprecated? || cask.disabled?

user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online?
return if user.nil?
return if user.nil? || repo.nil?

odebug "Auditing GitLab repo archived"

Expand All @@ -810,7 +810,7 @@ def audit_github_repository
return unless new_cask?

user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*})
return if user.nil?
return if user.nil? || repo.nil?

odebug "Auditing GitHub repo"

Expand All @@ -823,7 +823,7 @@ def audit_gitlab_repository
return unless new_cask?

user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*})
return if user.nil?
return if user.nil? || repo.nil?

odebug "Auditing GitLab repo"

Expand All @@ -836,7 +836,7 @@ def audit_bitbucket_repository
return unless new_cask?

user, repo = get_repo_data(%r{https?://bitbucket\.org/([^/]+)/([^/]+)/?.*})
return if user.nil?
return if user.nil? || repo.nil?

odebug "Auditing Bitbucket repo"

Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/extend/os/mac/utils/bottles.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module Utils
Expand All @@ -21,6 +21,7 @@ class Collector

alias generic_find_matching_tag find_matching_tag

sig { params(tag: Utils::Bottles::Tag, no_older_versions: T::Boolean).returns(T.nilable(Utils::Bottles::Tag)) }
def find_matching_tag(tag, no_older_versions: false)
# Used primarily by developers testing beta macOS releases.
if no_older_versions ||
Expand All @@ -35,6 +36,7 @@ def find_matching_tag(tag, no_older_versions: false)
end

# Find a bottle built for a previous version of macOS.
sig { params(tag: Utils::Bottles::Tag).returns(T.nilable(Utils::Bottles::Tag)) }
def find_older_compatible_tag(tag)
tag_version = begin
tag.to_macos_version
Expand Down
20 changes: 9 additions & 11 deletions Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,13 @@
metadata = SharedAudits.eol_data(name, formula.version.major)
metadata ||= SharedAudits.eol_data(name, formula.version.major_minor)

return if metadata.blank? || metadata["eol"] == false
return if metadata.blank? || (eol_date = metadata["eol"]).blank?

see_url = "see #{Formatter.url("https://endoflife.date/#{name}")}"
if metadata["eol"] == true
problem "Product is EOL, #{see_url}"
return
end
message = "Product is EOL"
message += " since #{eol_date}" if Date.parse(eol_date.to_s) <= Date.today

Check warning on line 588 in Library/Homebrew/formula_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_auditor.rb#L587-L588

Added lines #L587 - L588 were not covered by tests
message += ", see #{Formatter.url("https://endoflife.date/#{name}")}"

problem "Product is EOL since #{metadata["eol"]}, #{see_url}" if Date.parse(metadata["eol"]) <= Date.today
problem message
end

def audit_wayback_url
Expand Down Expand Up @@ -778,8 +776,8 @@
problem "#{stable.version} is a development release"

when %r{https?://gitlab\.com/([\w-]+)/([\w-]+)}
owner = Regexp.last_match(1)
repo = Regexp.last_match(2)
owner = T.must(Regexp.last_match(1))
repo = T.must(Regexp.last_match(2))

tag = SharedAudits.gitlab_tag_from_url(url)
tag ||= stable.specs[:tag]
Expand All @@ -790,8 +788,8 @@
problem error if error
end
when %r{^https://github.com/([\w-]+)/([\w-]+)}
owner = Regexp.last_match(1)
repo = Regexp.last_match(2)
owner = T.must(Regexp.last_match(1))
repo = T.must(Regexp.last_match(2))
tag = SharedAudits.github_tag_from_url(url)
tag ||= formula.stable.specs[:tag]

Expand Down
18 changes: 12 additions & 6 deletions Library/Homebrew/metafiles.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# typed: true
# typed: strict
# frozen_string_literal: true

# Helper for checking if a file is considered a metadata file.
module Metafiles
LICENSES = Set.new(%w[copying copyright license licence]).freeze
LICENSES = T.let(Set.new(%w[copying copyright license licence]).freeze, T::Set[String])
# {https://github.com/github/markup#markups}
EXTENSIONS = Set.new(%w[
EXTENSIONS = T.let(Set.new(%w[
.adoc .asc .asciidoc .creole .html .markdown .md .mdown .mediawiki .mkdn
.org .pod .rdoc .rst .rtf .textile .txt .wiki
]).freeze
BASENAMES = Set.new(%w[about authors changelog changes history news notes notice readme todo]).freeze
]).freeze, T::Set[String])
BASENAMES = T.let(Set.new(%w[
about authors changelog changes history news notes notice readme todo
]).freeze, T::Set[String])

module_function

sig { params(file: String).returns(T::Boolean) }
def list?(file)
return false if %w[.DS_Store INSTALL_RECEIPT.json].include?(file)

!copy?(file)
end

sig { params(file: String).returns(T::Boolean) }
def copy?(file)
file = file.downcase
return true if LICENSES.include? file.split(/\.|-/).first
license = file.split(/\.|-/).first
return false unless license
return true if LICENSES.include?(license)

ext = File.extname(file)
file = File.basename(file, ext) if EXTENSIONS.include?(ext)
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/missing_formula.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "formulary"
Expand All @@ -7,11 +7,13 @@ module Homebrew
# Helper module for checking if there is a reason a formula is missing.
module MissingFormula
class << self
sig { params(name: String, silent: T::Boolean, show_info: T::Boolean).returns(T.nilable(String)) }
def reason(name, silent: false, show_info: false)
cask_reason(name, silent:, show_info:) || disallowed_reason(name) ||
tap_migration_reason(name) || deleted_reason(name, silent:)
end

sig { params(name: String).returns(T.nilable(String)) }
def disallowed_reason(name)
case name.downcase
when "gem", /^rubygems?$/ then <<~EOS
Expand Down Expand Up @@ -93,6 +95,7 @@ def disallowed_reason(name)
end
alias generic_disallowed_reason disallowed_reason

sig { params(name: String).returns(T.nilable(String)) }
def tap_migration_reason(name)
message = T.let(nil, T.nilable(String))

Expand Down Expand Up @@ -127,6 +130,7 @@ def tap_migration_reason(name)
message
end

sig { params(name: String, silent: T::Boolean).returns(T.nilable(String)) }
def deleted_reason(name, silent: false)
path = Formulary.path name
return if File.exist? path
Expand Down
14 changes: 12 additions & 2 deletions Library/Homebrew/readall.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "formula"
Expand All @@ -16,6 +16,7 @@ module Readall

private_class_method :cache

sig { params(ruby_files: T::Array[Pathname]).returns(T::Boolean) }
def self.valid_ruby_syntax?(ruby_files)
failed = T.let(false, T::Boolean)
ruby_files.each do |ruby_file|
Expand All @@ -25,6 +26,7 @@ def self.valid_ruby_syntax?(ruby_files)
!failed
end

sig { params(alias_dir: Pathname, formula_dir: Pathname).returns(T::Boolean) }
def self.valid_aliases?(alias_dir, formula_dir)
return true unless alias_dir.directory?

Expand All @@ -46,6 +48,7 @@ def self.valid_aliases?(alias_dir, formula_dir)
!failed
end

sig { params(tap: Tap, bottle_tag: T.nilable(Utils::Bottles::Tag)).returns(T::Boolean) }
def self.valid_formulae?(tap, bottle_tag: nil)
cache[:valid_formulae] ||= {}

Expand All @@ -55,7 +58,7 @@ def self.valid_formulae?(tap, bottle_tag: nil)
next if valid == true || valid&.include?(bottle_tag)

formula_name = file.basename(".rb").to_s
formula_contents = file.read(encoding: "UTF-8")
formula_contents = file.read.force_encoding("UTF-8")

readall_namespace = "ReadallNamespace"
readall_formula_class = Formulary.load_formula(formula_name, file, formula_contents, readall_namespace,
Expand All @@ -79,10 +82,16 @@ def self.valid_formulae?(tap, bottle_tag: nil)
success
end

sig { params(_tap: Tap, os_name: T.nilable(Symbol), arch: T.nilable(Symbol)).returns(T::Boolean) }
def self.valid_casks?(_tap, os_name: nil, arch: nil)
true
end

sig {
params(
tap: Tap, aliases: T::Boolean, no_simulate: T::Boolean, os_arch_combinations: T::Array[T::Array[String]],
).returns(T::Boolean)
}
def self.valid_tap?(tap, aliases: false, no_simulate: false,
os_arch_combinations: OnSystem::ALL_OS_ARCH_COMBINATIONS)
success = true
Expand Down Expand Up @@ -110,6 +119,7 @@ def self.valid_tap?(tap, aliases: false, no_simulate: false,
success
end

sig { params(filename: Pathname).returns(T::Boolean) }
private_class_method def self.syntax_errors_or_warnings?(filename)
# Retrieve messages about syntax errors/warnings printed to `$stderr`.
_, err, status = system_command(RUBY_PATH, args: ["-c", "-w", filename], print_stderr: false)
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/unlink.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module Homebrew
# Provides helper methods for unlinking formulae and kegs with consistent output.
module Unlink
sig { params(formula: Formula, verbose: T::Boolean).void }
def self.unlink_versioned_formulae(formula, verbose: false)
formula.versioned_formulae
.select(&:keg_only?)
Expand All @@ -15,6 +16,7 @@ def self.unlink_versioned_formulae(formula, verbose: false)
end
end

sig { params(keg: Keg, dry_run: T::Boolean, verbose: T::Boolean).void }
def self.unlink(keg, dry_run: false, verbose: false)
options = { dry_run:, verbose: }

Expand Down
9 changes: 8 additions & 1 deletion Library/Homebrew/utils/link.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module Utils
# Helper functions for creating symlinks.
module Link
sig { params(src_dir: Pathname, dst_dir: Pathname, command: String, link_dir: T::Boolean).void }
def self.link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
return unless src_dir.exist?

Expand Down Expand Up @@ -38,6 +39,7 @@ def self.link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
end
private_class_method :link_src_dst_dirs

sig { params(src_dir: Pathname, dst_dir: Pathname, unlink_dir: T::Boolean).void }
def self.unlink_src_dst_dirs(src_dir, dst_dir, unlink_dir: false)
return unless src_dir.exist?

Expand All @@ -52,26 +54,31 @@ def self.unlink_src_dst_dirs(src_dir, dst_dir, unlink_dir: false)
end
private_class_method :unlink_src_dst_dirs

sig { params(path: Pathname, command: String).void }
def self.link_manpages(path, command)
link_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1", command)
end

sig { params(path: Pathname).void }
def self.unlink_manpages(path)
unlink_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1")
end

sig { params(path: Pathname, command: String).void }
def self.link_completions(path, command)
link_src_dst_dirs(path/"completions/bash", HOMEBREW_PREFIX/"etc/bash_completion.d", command)
link_src_dst_dirs(path/"completions/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions", command)
link_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d", command)
end

sig { params(path: Pathname).void }
def self.unlink_completions(path)
unlink_src_dst_dirs(path/"completions/bash", HOMEBREW_PREFIX/"etc/bash_completion.d")
unlink_src_dst_dirs(path/"completions/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions")
unlink_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
end

sig { params(path: Pathname, command: String).void }
def self.link_docs(path, command)
link_src_dst_dirs(path/"docs", HOMEBREW_PREFIX/"share/doc/homebrew", command, link_dir: true)
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/utils/service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module Utils
Expand Down Expand Up @@ -27,7 +27,7 @@ def self.launchctl
return @launchctl if defined? @launchctl
return if ENV["HOMEBREW_TEST_GENERIC_OS"]

@launchctl = which("launchctl")
@launchctl = T.let(which("launchctl"), T.nilable(Pathname))
end

# Path to systemctl binary.
Expand All @@ -36,7 +36,7 @@ def self.systemctl
return @systemctl if defined? @systemctl
return if ENV["HOMEBREW_TEST_GENERIC_OS"]

@systemctl = which("systemctl")
@systemctl = T.let(which("systemctl"), T.nilable(Pathname))
end

sig { returns(T::Boolean) }
Expand Down
Loading