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

Replace ActiveSupport inflections with Utils methods #14778

Merged
merged 19 commits into from Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/cmd/install.rb
Expand Up @@ -85,7 +85,7 @@ def self.install_casks(

if dry_run
if (casks_to_install = casks.reject(&:installed?).presence)
plural = "cask".pluralize(casks_to_install.count)
plural = ::Utils.pluralize("cask", casks_to_install.count)
ohai "Would install #{casks_to_install.count} #{plural}:"
puts casks_to_install.map(&:full_name).join(" ")
end
Expand All @@ -97,7 +97,7 @@ def self.install_casks(
.map(&:name)
next if dep_names.blank?

plural = "dependency".pluralize(dep_names.count)
plural = ::Utils.pluralize("dependenc", dep_names.count, plural: "ies", singular: "y")
ohai "Would install #{dep_names.count} #{plural} for #{cask.full_name}:"
puts dep_names.join(" ")
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd/uninstall.rb
Expand Up @@ -46,7 +46,7 @@ def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false)
next if (versions = cask.versions).empty?

puts <<~EOS
#{cask} #{versions.to_sentence} #{"is".pluralize(versions.count)} still installed.
#{cask} #{versions.to_sentence} #{(versions.count == 1) ? "is" : "are"} still installed.
Remove #{(versions.count == 1) ? "it" : "them all"} with `brew uninstall --cask --force #{cask}`.
EOS
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/cmd/upgrade.rb
Expand Up @@ -121,7 +121,7 @@ def self.upgrade_casks(

if manual_installer_casks.present?
count = manual_installer_casks.count
ofail "Not upgrading #{count} `installer manual` #{"cask".pluralize(count)}."
ofail "Not upgrading #{count} `installer manual` #{::Utils.pluralize("cask", versions.count)}."
puts manual_installer_casks.map(&:to_s)
outdated_casks -= manual_installer_casks
end
Expand All @@ -142,7 +142,7 @@ def self.upgrade_casks(
end

verb = dry_run ? "Would upgrade" : "Upgrading"
oh1 "#{verb} #{outdated_casks.count} outdated #{"package".pluralize(outdated_casks.count)}:"
oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils.pluralize("package", outdated_casks.count)}:"

caught_exceptions = []

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/installer.rb
Expand Up @@ -231,7 +231,7 @@ def install_artifacts
already_installed_artifacts = []

odebug "Installing artifacts"
odebug "#{artifacts.length} #{"artifact".pluralize(artifacts.length)} defined", artifacts
odebug "#{artifacts.length} #{::Utils.pluralize("artifact", artifacts.length)} defined", artifacts

artifacts.each do |artifact|
next unless artifact.respond_to?(:install_phase)
Expand Down Expand Up @@ -460,7 +460,7 @@ def uninstall_artifacts(clear: false)
artifacts = @cask.artifacts

odebug "Uninstalling artifacts"
odebug "#{artifacts.length} #{"artifact".pluralize(artifacts.length)} defined", artifacts
odebug "#{artifacts.length} #{::Utils.pluralize("artifact", artifacts.length)} defined", artifacts

artifacts.each do |artifact|
if artifact.respond_to?(:uninstall_phase)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cleanup.rb
Expand Up @@ -584,7 +584,7 @@ def self.autoremove(dry_run: false)
formulae_names = removable_formulae.map(&:full_name).sort

verb = dry_run ? "Would autoremove" : "Autoremoving"
oh1 "#{verb} #{formulae_names.count} unneeded #{"formula".pluralize(formulae_names.count)}:"
oh1 "#{verb} #{formulae_names.count} unneeded #{Utils.pluralize("formula", formulae_names.count, plural: "e")}:"
puts formulae_names.join("\n")
return if dry_run

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cli/parser.rb
Expand Up @@ -684,7 +684,7 @@ def initialize(maximum, types: [])
arg_types = types.map { |type| type.to_s.tr("_", " ") }
.to_sentence two_words_connector: " or ", last_word_connector: " or "

"This command does not take more than #{maximum} #{arg_types} #{"argument".pluralize(maximum)}."
"This command does not take more than #{maximum} #{arg_types} #{Utils.pluralize("argument", maximum)}."
end
end
end
Expand All @@ -698,7 +698,7 @@ def initialize(minimum, types: [])
arg_types = types.map { |type| type.to_s.tr("_", " ") }
.to_sentence two_words_connector: " or ", last_word_connector: " or "

super "This command requires at least #{minimum} #{arg_types} #{"argument".pluralize(minimum)}."
super "This command requires at least #{minimum} #{arg_types} #{Utils.pluralize("argument", minimum)}."
end
end

Expand All @@ -711,7 +711,7 @@ def initialize(minimum, types: [])
arg_types = types.map { |type| type.to_s.tr("_", " ") }
.to_sentence two_words_connector: " or ", last_word_connector: " or "

super "This command requires exactly #{minimum} #{arg_types} #{"argument".pluralize(minimum)}."
super "This command requires exactly #{minimum} #{arg_types} #{Utils.pluralize("argument", minimum)}."
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/developer.rb
Expand Up @@ -40,7 +40,7 @@ def developer
case args.named.first
when nil, "state"
if env_vars.any?
puts "Developer mode is enabled because #{env_vars.to_sentence} #{"is".pluralize(env_vars.count)} set."
puts "Developer mode is enabled because #{env_vars.to_sentence} #{(env_vars.count == 1) ? "is" : "are"} set."
elsif Homebrew::Settings.read("devcmdrun") == "true"
puts "Developer mode is enabled."
else
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/fetch.rb
Expand Up @@ -166,7 +166,7 @@ def retry_fetch?(f, args:)
if args.retry? && (@fetch_tries[f] < FETCH_MAX_TRIES)
wait = 2 ** @fetch_tries[f]
remaining = FETCH_MAX_TRIES - @fetch_tries[f]
what = "try".pluralize(remaining)
what = Utils.pluralize("tr", remaining, plural: "ies", singular: "y")

ohai "Retrying download in #{wait}s... (#{remaining} #{what} left)"
sleep wait
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/info.rb
Expand Up @@ -124,7 +124,7 @@ def print_statistics
return unless HOMEBREW_CELLAR.exist?

count = Formula.racks.length
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
puts "#{count} #{Utils.pluralize("keg", count)}, #{HOMEBREW_CELLAR.dup.abv}"
end

sig { params(args: CLI::Args).void }
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cmd/tap-info.rb
Expand Up @@ -57,10 +57,10 @@ def print_tap_info(taps)
command_count += tap.command_files.size
private_count += 1 if tap.private?
end
info = "#{tap_count} #{"tap".pluralize(tap_count)}"
info = "#{tap_count} #{Utils.pluralize("tap", tap_count)}"
info += ", #{private_count} private"
info += ", #{formula_count} #{"formula".pluralize(formula_count)}"
info += ", #{command_count} #{"command".pluralize(command_count)}"
info += ", #{formula_count} #{Utils.pluralize("formula", formula_count, plural: "e")}"
info += ", #{command_count} #{Utils.pluralize("command", command_count)}"
info += ", #{Tap::TAP_DIRECTORY.dup.abv}" if Tap::TAP_DIRECTORY.directory?
puts info
else
Expand Down
13 changes: 8 additions & 5 deletions Library/Homebrew/cmd/update-report.rb
Expand Up @@ -199,7 +199,8 @@ def output_update_report

unless updated_taps.empty?
auto_update_header args: args
puts "Updated #{updated_taps.count} #{"tap".pluralize(updated_taps.count)} (#{updated_taps.to_sentence})."
noun = Utils.pluralize("tap", updated_taps.count)
puts "Updated #{updated_taps.count} #{noun} (#{updated_taps.to_sentence})."
updated = true
end

Expand Down Expand Up @@ -584,11 +585,12 @@ def dump(updated_formula_report: true)
output_dump_formula_or_cask_report "Outdated Casks", outdated_casks
elsif report_all
if (changed_formulae = select_formula_or_cask(:M).count) && changed_formulae.positive?
ohai "Modified Formulae", "Modified #{changed_formulae} #{"formula".pluralize(changed_formulae)}."
noun = Utils.pluralize("formula", changed_formulae, plural: "e")
ohai "Modified Formulae", "Modified #{changed_formulae} #{noun}."
end

if (changed_casks = select_formula_or_cask(:MC).count) && changed_casks.positive?
ohai "Modified Casks", "Modified #{changed_casks} #{"cask".pluralize(changed_casks)}."
ohai "Modified Casks", "Modified #{changed_casks} #{Utils.pluralize("cask", changed_casks)}."
end
else
outdated_formulae = Formula.installed.select(&:outdated?).map(&:name)
Expand All @@ -609,12 +611,13 @@ def dump(updated_formula_report: true)
msg = ""

if outdated_formulae.positive?
msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{"formula".pluralize(outdated_formulae)}"
noun = Utils.pluralize("formula", outdated_formulae, plural: "e")
msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{noun}"
end

if outdated_casks.positive?
msg += " and " if msg.present?
msg += "#{Tty.bold}#{outdated_casks}#{Tty.reset} outdated #{"cask".pluralize(outdated_casks)}"
msg += "#{Tty.bold}#{outdated_casks}#{Tty.reset} outdated #{Utils.pluralize("cask", outdated_casks)}"
end

return if msg.blank?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/upgrade.rb
Expand Up @@ -172,15 +172,15 @@ def upgrade_outdated_formulae(formulae, args:)
end

if !pinned.empty? && !args.ignore_pinned?
ofail "Not upgrading #{pinned.count} pinned #{"package".pluralize(pinned.count)}:"
ofail "Not upgrading #{pinned.count} pinned #{Utils.pluralize("package", pinned.count)}:"
puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
end

if formulae_to_install.empty?
oh1 "No packages to upgrade"
else
verb = args.dry_run? ? "Would upgrade" : "Upgrading"
oh1 "#{verb} #{formulae_to_install.count} outdated #{"package".pluralize(formulae_to_install.count)}:"
oh1 "#{verb} #{formulae_to_install.count} outdated #{Utils.pluralize("package", formulae_to_install.count)}:"
formulae_upgrades = formulae_to_install.map do |f|
if f.optlinked?
"#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
Expand Down
13 changes: 8 additions & 5 deletions Library/Homebrew/dev-cmd/audit.rb
Expand Up @@ -277,19 +277,22 @@ def audit
if total_problems_count.positive?
puts new_formula_problem_lines.map { |s| " #{s}" }

errors_summary = "#{total_problems_count} #{"problem".pluralize(total_problems_count)}"
errors_summary = "#{total_problems_count} #{Utils.pluralize("problem", total_problems_count)}"

error_sources = []
error_sources << "#{formula_count} #{"formula".pluralize(formula_count)}" if formula_count.positive?
error_sources << "#{cask_count} #{"cask".pluralize(cask_count)}" if cask_count.positive?
error_sources << "#{tap_count} #{"tap".pluralize(tap_count)}" if tap_count.positive?
if formula_count.positive?
error_sources << "#{formula_count} #{Utils.pluralize("formula", formula_count, plural: "e")}"
end
error_sources << "#{cask_count} #{Utils.pluralize("cask", cask_count)}" if cask_count.positive?
error_sources << "#{tap_count} #{Utils.pluralize("tap", tap_count)}" if tap_count.positive?

errors_summary += " in #{error_sources.to_sentence}" if error_sources.any?

errors_summary += " detected"

if corrected_problem_count.positive?
errors_summary += ", #{corrected_problem_count} #{"problem".pluralize(corrected_problem_count)} corrected"
noun = Utils.pluralize("problem", corrected_problem_count)
errors_summary += ", #{corrected_problem_count} #{noun} corrected"
end

ofail errors_summary
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/pr-automerge.rb
Expand Up @@ -61,7 +61,7 @@ def pr_automerge
return
end

ohai "#{prs.count} matching pull #{"request".pluralize(prs.count)}:"
ohai "#{prs.count} matching pull #{Utils.pluralize("request", prs.count)}:"
pr_urls = []
prs.each do |pr|
puts "#{tap.full_name unless tap.core_tap?}##{pr["number"]}: #{pr["title"]}"
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/diagnostic.rb
Expand Up @@ -906,11 +906,11 @@ def check_cask_taps
0
end

"#{tap.path} (#{cask_count} #{"cask".pluralize(cask_count)})"
"#{tap.path} (#{cask_count} #{Utils.pluralize("cask", cask_count)})"
end
end)

taps = "tap".pluralize error_tap_paths.count
taps = Utils.pluralize("tap", error_tap_paths.count)
"Unable to read from cask #{taps}: #{error_tap_paths.to_sentence}" if error_tap_paths.present?
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/exceptions.rb
Expand Up @@ -568,7 +568,7 @@ def dump(verbose: false)
class UnbottledError < RuntimeError
def initialize(formulae)
msg = +<<~EOS
The following #{"formula".pluralize(formulae.count)} cannot be installed from #{"bottle".pluralize(formulae.count)} and must be
The following #{Utils.pluralize("formula", formulae.count, plural: "e")} cannot be installed from #{Utils.pluralize("bottle", formulae.count)} and must be
built from source.
#{formulae.to_sentence}
EOS
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/formulary.rb
Expand Up @@ -52,10 +52,10 @@ def self.clear_cache
next if type == :formulary_factory

cached_objects.each_value do |klass|
namespace = klass.name.deconstantize
next if namespace.deconstantize != name
namespace = Utils.deconstantize(klass.name)
next if Utils.deconstantize(namespace) != name

remove_const(namespace.demodulize)
remove_const(Utils.demodulize(namespace))
end
end

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/install.rb
Expand Up @@ -324,7 +324,7 @@ def install_formulae(

if dry_run
if (formulae_name_to_install = formulae_to_install.map(&:name))
plural = "formula".pluralize(formulae_name_to_install.count)
plural = Utils.pluralize("formula", formulae_name_to_install.count, plural: "e")
ohai "Would install #{formulae_name_to_install.count} #{plural}:"
puts formulae_name_to_install.join(" ")

Expand Down Expand Up @@ -354,7 +354,7 @@ def install_formula(formula_installer)
def print_dry_run_dependencies(formula, dependencies, &block)
return if dependencies.empty?

plural = "dependency".pluralize(dependencies.count)
plural = Utils.pluralize("dependenc", dependencies.count, plural: "ies", singular: "y")
ohai "Would install #{dependencies.count} #{plural} for #{formula.name}:"
formula_names = dependencies.map(&:first).map(&:to_formula).map(&block)
puts formula_names.join(" ")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/livecheck/livecheck.rb
Expand Up @@ -61,7 +61,7 @@ def livecheck_strategy_names
constant = Strategy.const_get(const_symbol)
next unless constant.is_a?(Class)

@livecheck_strategy_names[constant] = T.must(constant.name).demodulize
@livecheck_strategy_names[constant] = Utils.demodulize(T.must(constant.name))
end
@livecheck_strategy_names.freeze
end
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/livecheck/strategy/electron_builder.rb
Expand Up @@ -73,7 +73,8 @@ def self.versions_from_content(content, regex = nil, &block)
}
def self.find_versions(url:, regex: nil, **_unused, &block)
if regex.present? && block.blank?
raise ArgumentError, "#{T.must(name).demodulize} only supports a regex when using a `strategy` block"
raise ArgumentError,
"#{Utils.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
end

match_data = { matches: {}, regex: regex, url: url }
Expand Down
7 changes: 5 additions & 2 deletions Library/Homebrew/livecheck/strategy/extract_plist.rb
Expand Up @@ -97,9 +97,12 @@ def self.versions_from_items(items, regex = nil, &block)
}
def self.find_versions(cask:, url: nil, regex: nil, **_unused, &block)
if regex.present? && block.blank?
raise ArgumentError, "#{T.must(name).demodulize} only supports a regex when using a `strategy` block"
raise ArgumentError,
"#{Utils.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
end
unless T.unsafe(cask)
raise ArgumentError, "The #{Utils.demodulize(T.must(name))} strategy only supports casks."
end
raise ArgumentError, "The #{T.must(name).demodulize} strategy only supports casks." unless T.unsafe(cask)

match_data = { matches: {}, regex: regex, url: url }

Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/livecheck/strategy/git.rb
Expand Up @@ -103,7 +103,8 @@ def self.versions_from_tags(tags, regex = nil, &block)
tags.map do |tag|
if regex
# Use the first capture group (the version)
tag.scan(regex).first&.first
# This code is not typesafe unless the regex includes a capture group
T.unsafe(tag.scan(regex).first)&.first
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a type error that appears when deleting String#first from the active support rbi below (but I don't think this code uses that path, looking at call sites).

else
# Remove non-digits from the start of the tag and use that as the
# version text
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/livecheck/strategy/json.rb
Expand Up @@ -100,7 +100,7 @@ def self.versions_from_content(content, regex = nil, &block)
).returns(T::Hash[Symbol, T.untyped])
}
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **_unused, &block)
raise ArgumentError, "#{T.must(name).demodulize} requires a `strategy` block" if block.blank?
raise ArgumentError, "#{Utils.demodulize(T.must(name))} requires a `strategy` block" if block.blank?

match_data = { matches: {}, regex: regex, url: url }
return match_data if url.blank? || block.blank?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/livecheck/strategy/page_match.rb
Expand Up @@ -93,7 +93,7 @@ def self.versions_from_content(content, regex, &block)
}
def self.find_versions(url:, regex: nil, provided_content: nil, homebrew_curl: false, **_unused, &block)
if regex.blank? && block.blank?
raise ArgumentError, "#{T.must(name).demodulize} requires a regex or `strategy` block"
raise ArgumentError, "#{Utils.demodulize(T.must(name))} requires a regex or `strategy` block"
end

match_data = { matches: {}, regex: regex, url: url }
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/livecheck/strategy/sparkle.rb
Expand Up @@ -203,7 +203,8 @@ def self.versions_from_content(content, regex = nil, &block)
}
def self.find_versions(url:, regex: nil, **_unused, &block)
if regex.present? && block.blank?
raise ArgumentError, "#{T.must(name).demodulize} only supports a regex when using a `strategy` block"
raise ArgumentError,
"#{Utils.demodulize(T.must(name))} only supports a regex when using a `strategy` block"
end

match_data = { matches: {}, regex: regex, url: url }
Expand Down