From 07091cfbeaf1080643ce4c5260d598b591436633 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 12 Sep 2025 09:02:36 +0100 Subject: [PATCH] Simplify pluralisation of common words Formulae, dependencies, tries are all used in multiple places so let's simplify them --- Library/Homebrew/cleanup.rb | 2 +- Library/Homebrew/cmd/install.rb | 4 ++-- Library/Homebrew/cmd/tap-info.rb | 2 +- Library/Homebrew/cmd/update-report.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 4 +--- Library/Homebrew/exceptions.rb | 2 +- Library/Homebrew/install.rb | 9 ++++----- Library/Homebrew/retryable_download.rb | 2 +- Library/Homebrew/search.rb | 2 +- Library/Homebrew/tap.rb | 2 +- Library/Homebrew/upgrade.rb | 2 +- Library/Homebrew/utils.rb | 9 +++++++++ 12 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index c48f2320fe..27042bea0d 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -733,7 +733,7 @@ module Homebrew formulae_names = removable_formulae.map(&:full_name).sort verb = dry_run ? "Would autoremove" : "Autoremoving" - oh1 "#{verb} #{formulae_names.count} unneeded #{Utils.pluralize("formula", formulae_names.count, plural: "e")}:" + oh1 "#{verb} #{formulae_names.count} unneeded #{Utils.pluralize("formula", formulae_names.count)}:" puts formulae_names.join("\n") return if dry_run diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 5f187843c5..1852698e23 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -233,8 +233,8 @@ module Homebrew .map(&:name) next if dep_names.blank? - ohai "Would install #{::Utils.pluralize("dependenc", dep_names.count, plural: "ies", singular: "y", - include_count: true)} for #{cask.full_name}:" + ohai "Would install #{::Utils.pluralize("dependency", dep_names.count, include_count: true)} " \ + "for #{cask.full_name}:" puts dep_names.join(" ") end return diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index 8aacf5c6e9..384336d3b8 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -57,7 +57,7 @@ module Homebrew end info = Utils.pluralize("tap", tap_count, include_count: true) info += ", #{private_count} private" - info += ", #{Utils.pluralize("formula", formula_count, plural: "e", include_count: true)}" + info += ", #{Utils.pluralize("formula", formula_count, include_count: true)}" info += ", #{Utils.pluralize("command", command_count, include_count: true)}" info += ", #{HOMEBREW_TAP_DIRECTORY.dup.abv}" if HOMEBREW_TAP_DIRECTORY.directory? puts info diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 13bed07d10..28b171950b 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -842,7 +842,7 @@ class ReporterHub msg = "" if outdated_formulae.positive? - noun = Utils.pluralize("formula", outdated_formulae, plural: "e") + noun = Utils.pluralize("formula", outdated_formulae) msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{noun}" end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index f49be1d446..cd3728285b 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -294,9 +294,7 @@ module Homebrew errors_summary = Utils.pluralize("problem", total_problems_count, include_count: true) error_sources = [] - if formula_count.positive? - error_sources << Utils.pluralize("formula", formula_count, plural: "e", include_count: true) - end + error_sources << Utils.pluralize("formula", formula_count, include_count: true) if formula_count.positive? error_sources << Utils.pluralize("cask", cask_count, include_count: true) if cask_count.positive? error_sources << Utils.pluralize("tap", tap_count, include_count: true) if tap_count.positive? diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 394f92ff68..2e72587d1e 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -579,7 +579,7 @@ class UnbottledError < RuntimeError require "utils" msg = <<~EOS - The following #{Utils.pluralize("formula", formulae.count, plural: "e")} cannot be installed from #{Utils.pluralize("bottle", formulae.count)} and must be + The following #{Utils.pluralize("formula", formulae.count)} cannot be installed from #{Utils.pluralize("bottle", formulae.count)} and must be built from source. #{formulae.to_sentence} EOS diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 4c46a38075..7b846433dc 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -405,8 +405,7 @@ module Homebrew return if formulae_names_to_install.empty? if dry_run - ohai "Would install #{Utils.pluralize("formula", formulae_names_to_install.count, - plural: "e", include_count: true)}:" + ohai "Would install #{Utils.pluralize("formula", formulae_names_to_install.count, include_count: true)}:" puts formulae_names_to_install.join(" ") formula_installers.each do |fi| @@ -429,8 +428,8 @@ module Homebrew def print_dry_run_dependencies(formula, dependencies) return if dependencies.empty? - ohai "Would install #{Utils.pluralize("dependenc", dependencies.count, plural: "ies", singular: "y", - include_count: true)} for #{formula.name}:" + ohai "Would install #{Utils.pluralize("dependency", dependencies.count, include_count: true)} " \ + "for #{formula.name}:" formula_names = dependencies.map { |(dep, _options)| yield dep.to_formula } puts formula_names.join(" ") end @@ -446,7 +445,7 @@ module Homebrew sizes = compute_total_sizes(formulae, debug: args.debug?) - puts "#{::Utils.pluralize("Formula", formulae.count, plural: "e")} \ + puts "#{::Utils.pluralize("Formula", formulae.count)} \ (#{formulae.count}): #{formulae.join(", ")}\n\n" puts "Download Size: #{disk_usage_readable(sizes.fetch(:download))}" puts "Install Size: #{disk_usage_readable(sizes.fetch(:installed))}" diff --git a/Library/Homebrew/retryable_download.rb b/Library/Homebrew/retryable_download.rb index 0428e1d104..002cacc7b6 100644 --- a/Library/Homebrew/retryable_download.rb +++ b/Library/Homebrew/retryable_download.rb @@ -93,7 +93,7 @@ module Homebrew wait = 2 ** @try unless quiet - what = Utils.pluralize("tr", tries_remaining, plural: "ies", singular: "y") + what = Utils.pluralize("try", tries_remaining) ohai "Retrying download in #{wait}s... (#{tries_remaining} #{what} left)" end sleep wait diff --git a/Library/Homebrew/search.rb b/Library/Homebrew/search.rb index 362079307b..5d8bf609b1 100644 --- a/Library/Homebrew/search.rb +++ b/Library/Homebrew/search.rb @@ -34,7 +34,7 @@ module Homebrew unofficial = Tap.all.sum { |tap| tap.official? ? 0 : tap.formula_files.size } if unofficial.positive? opoo "Use `--eval-all` to search #{unofficial} additional " \ - "#{Utils.pluralize("formula", unofficial, plural: "e")} in third party taps." + "#{Utils.pluralize("formula", unofficial)} in third party taps." end descriptions = Homebrew::API::Formula.all_formulae.transform_values { |data| data["desc"] } Descriptions.search(string_or_regex, search_type, descriptions, eval_all, cache_store_hash: true).print diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 0c14f6ce6d..ab0ae9b6ee 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -738,7 +738,7 @@ class Tap end if (formula_count = formula_files.count).positive? - contents << Utils.pluralize("formula", formula_count, plural: "e", include_count: true) + contents << Utils.pluralize("formula", formula_count, include_count: true) end contents diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index c3ce323abc..1f8c44eb68 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -251,7 +251,7 @@ module Homebrew ohai "No outdated dependents to upgrade!" unless dry_run else installed_formulae = (dry_run ? formulae : FormulaInstaller.installed.to_a).dup - formula_plural = Utils.pluralize("formula", installed_formulae.count, plural: "e") + formula_plural = Utils.pluralize("formula", installed_formulae.count) upgrade_verb = dry_run ? "Would upgrade" : "Upgrading" ohai "#{upgrade_verb} #{Utils.pluralize("dependent", upgradeable.count, include_count: true)} of upgraded #{formula_plural}:" diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 0287a54ff7..d1214c936c 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -160,6 +160,15 @@ module Utils params(stem: String, count: Integer, plural: String, singular: String, include_count: T::Boolean).returns(String) } def self.pluralize(stem, count, plural: "s", singular: "", include_count: false) + case stem + when "formula" + plural = "e" + when "dependency", "try" + stem = stem.delete_suffix("y") + plural = "ies" + singular = "y" + end + prefix = include_count ? "#{count} " : "" suffix = (count == 1) ? singular : plural "#{prefix}#{stem}#{suffix}"