extend/kernel: tighten up some type signatures
Allowing either `Formula`e or `String`s in these methods leads to errors at runtime when one hasn't done `require "formula"` yet. Let's tighten these up so that they only accept `Formula` arguments to guarantee that `require "formula"` has been done before they are called. For callers that need to pass a `String`, we update them to call a version of these methods that accepts only `String`s. See discussion at #20352.
This commit is contained in:
parent
d746234dcd
commit
a76c33f7bb
@ -371,9 +371,9 @@ module Homebrew
|
||||
def decorate_dependencies(dependencies)
|
||||
deps_status = dependencies.map do |dep|
|
||||
if dep.satisfied?([])
|
||||
pretty_installed(dep_display_s(dep))
|
||||
pretty_installed_string(dep_display_s(dep))
|
||||
else
|
||||
pretty_uninstalled(dep_display_s(dep))
|
||||
pretty_uninstalled_string(dep_display_s(dep))
|
||||
end
|
||||
end
|
||||
deps_status.join(", ")
|
||||
|
||||
@ -903,7 +903,7 @@ class ReporterHub
|
||||
sig { void }
|
||||
def dump_deleted_formula_report
|
||||
formulae = select_formula_or_cask(:D).sort.filter_map do |name|
|
||||
pretty_uninstalled(name) if installed?(name)
|
||||
pretty_uninstalled_string(name) if installed?(name)
|
||||
end
|
||||
|
||||
output_dump_formula_or_cask_report "Deleted Installed Formulae", formulae
|
||||
@ -915,7 +915,7 @@ class ReporterHub
|
||||
|
||||
casks = select_formula_or_cask(:DC).sort.filter_map do |name|
|
||||
name = T.must(name.split("/").last)
|
||||
pretty_uninstalled(name) if cask_installed?(name)
|
||||
pretty_uninstalled_string(name) if cask_installed?(name)
|
||||
end
|
||||
|
||||
output_dump_formula_or_cask_report "Deleted Installed Casks", casks
|
||||
|
||||
@ -234,36 +234,51 @@ module Kernel
|
||||
odeprecated(method, replacement, disable: true, disable_on:, disable_for_developers:, caller:)
|
||||
end
|
||||
|
||||
sig { params(formula: T.any(String, Formula)).returns(String) }
|
||||
sig { params(formula: Formula).returns(String) }
|
||||
def pretty_installed(formula)
|
||||
pretty_installed_string(formula.to_s)
|
||||
end
|
||||
|
||||
sig { params(string: String).returns(String) }
|
||||
def pretty_installed_string(string)
|
||||
if !$stdout.tty?
|
||||
formula.to_s
|
||||
string
|
||||
elsif Homebrew::EnvConfig.no_emoji?
|
||||
Formatter.success("#{Tty.bold}#{formula} (installed)#{Tty.reset}")
|
||||
Formatter.success("#{Tty.bold}#{string} (installed)#{Tty.reset}")
|
||||
else
|
||||
"#{Tty.bold}#{formula} #{Formatter.success("✔")}#{Tty.reset}"
|
||||
"#{Tty.bold}#{string} #{Formatter.success("✔")}#{Tty.reset}"
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(formula: T.any(String, Formula)).returns(String) }
|
||||
sig { params(formula: Formula).returns(String) }
|
||||
def pretty_outdated(formula)
|
||||
pretty_outdated_string(formula.to_s)
|
||||
end
|
||||
|
||||
sig { params(string: String).returns(String) }
|
||||
def pretty_outdated_string(string)
|
||||
if !$stdout.tty?
|
||||
formula.to_s
|
||||
string
|
||||
elsif Homebrew::EnvConfig.no_emoji?
|
||||
Formatter.error("#{Tty.bold}#{formula} (outdated)#{Tty.reset}")
|
||||
Formatter.error("#{Tty.bold}#{string} (outdated)#{Tty.reset}")
|
||||
else
|
||||
"#{Tty.bold}#{formula} #{Formatter.warning("⚠")}#{Tty.reset}"
|
||||
"#{Tty.bold}#{string} #{Formatter.warning("⚠")}#{Tty.reset}"
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(formula: T.any(String, Formula)).returns(String) }
|
||||
sig { params(formula: Formula).returns(String) }
|
||||
def pretty_uninstalled(formula)
|
||||
pretty_uninstalled_string(formula.to_s)
|
||||
end
|
||||
|
||||
sig { params(string: String).returns(String) }
|
||||
def pretty_uninstalled_string(string)
|
||||
if !$stdout.tty?
|
||||
formula.to_s
|
||||
string
|
||||
elsif Homebrew::EnvConfig.no_emoji?
|
||||
Formatter.error("#{Tty.bold}#{formula} (uninstalled)#{Tty.reset}")
|
||||
Formatter.error("#{Tty.bold}#{string} (uninstalled)#{Tty.reset}")
|
||||
else
|
||||
"#{Tty.bold}#{formula} #{Formatter.error("✘")}#{Tty.reset}"
|
||||
"#{Tty.bold}#{string} #{Formatter.error("✘")}#{Tty.reset}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user