diff --git a/Library/Homebrew/cask/cmd/uninstall.rb b/Library/Homebrew/cask/cmd/uninstall.rb index f121cbb98c..dbbdd328d5 100644 --- a/Library/Homebrew/cask/cmd/uninstall.rb +++ b/Library/Homebrew/cask/cmd/uninstall.rb @@ -46,7 +46,7 @@ module Cask next if (versions = cask.versions).empty? puts <<~EOS - #{cask} #{versions.to_sentence} #{::Utils.pluralize("", versions.count, plural: "are", singular: "is")} 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 diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index 9200926973..d4caa561e9 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -142,8 +142,7 @@ module Cask end verb = dry_run ? "Would upgrade" : "Upgrading" - oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils.pluralize("package", - outdated_casks.count)}:" + oh1 "#{verb} #{outdated_casks.count} outdated #{::Utils.pluralize("package", outdated_casks.count)}:" caught_exceptions = [] diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 3964dc5a4b..548dbf095a 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -584,8 +584,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, plural: "e")}:" puts formulae_names.join("\n") return if dry_run diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index ea9a898200..cd3c98f735 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -684,8 +684,7 @@ module Homebrew 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} #{Utils.pluralize("argument", - maximum)}." + "This command does not take more than #{maximum} #{arg_types} #{Utils.pluralize("argument", maximum)}." end end end @@ -699,8 +698,7 @@ module Homebrew 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} #{Utils.pluralize("argument", - minimum)}." + super "This command requires at least #{minimum} #{arg_types} #{Utils.pluralize("argument", minimum)}." end end @@ -713,8 +711,7 @@ module Homebrew 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} #{Utils.pluralize("argument", - minimum)}." + super "This command requires exactly #{minimum} #{arg_types} #{Utils.pluralize("argument", minimum)}." end end end diff --git a/Library/Homebrew/cmd/developer.rb b/Library/Homebrew/cmd/developer.rb index 03d0561573..60e1ef744a 100755 --- a/Library/Homebrew/cmd/developer.rb +++ b/Library/Homebrew/cmd/developer.rb @@ -40,8 +40,7 @@ module Homebrew case args.named.first when nil, "state" if env_vars.any? - verb = Utils.pluralize("", env_vars.count, plural: "are", singular: "is") - puts "Developer mode is enabled because #{env_vars.to_sentence} #{verb} 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 diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 69efca25f3..4d548e3d5e 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -199,8 +199,8 @@ module Homebrew unless updated_taps.empty? auto_update_header args: args - puts "Updated #{updated_taps.count} #{Utils.pluralize("tap", - 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 @@ -585,8 +585,8 @@ class ReporterHub 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} #{Utils.pluralize("formula", changed_formulae, plural: "e")}." + 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? @@ -611,14 +611,13 @@ class ReporterHub msg = "" if outdated_formulae.positive? - msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{Utils.pluralize("formula", - outdated_formulae, plural: "e")}" + 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 #{Utils.pluralize("cask", - outdated_casks)}" + msg += "#{Tty.bold}#{outdated_casks}#{Tty.reset} outdated #{Utils.pluralize("cask", outdated_casks)}" end return if msg.blank? diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 9016bc9706..94323b369f 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -180,8 +180,7 @@ module Homebrew oh1 "No packages to upgrade" else verb = args.dry_run? ? "Would upgrade" : "Upgrading" - oh1 "#{verb} #{formulae_to_install.count} outdated #{Utils.pluralize("package", - 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}" diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index e37b5d7f23..c5dac1cb53 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -281,8 +281,7 @@ module Homebrew error_sources = [] if formula_count.positive? - error_sources << "#{formula_count} #{Utils.pluralize("formula", formula_count, - plural: "e")}" + 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? @@ -292,8 +291,8 @@ module Homebrew errors_summary += " detected" if corrected_problem_count.positive? - errors_summary += ", #{corrected_problem_count} #{Utils.pluralize("problem", - corrected_problem_count)} corrected" + noun = Utils.pluralize("problem", corrected_problem_count) + errors_summary += ", #{corrected_problem_count} #{noun} corrected" end ofail errors_summary diff --git a/Library/Homebrew/livecheck/strategy/extract_plist.rb b/Library/Homebrew/livecheck/strategy/extract_plist.rb index b9025dfbe7..842e966571 100644 --- a/Library/Homebrew/livecheck/strategy/extract_plist.rb +++ b/Library/Homebrew/livecheck/strategy/extract_plist.rb @@ -101,8 +101,7 @@ module Homebrew "#{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." + raise ArgumentError, "The #{Utils.demodulize(T.must(name))} strategy only supports casks." end match_data = { matches: {}, regex: regex, url: url } diff --git a/Library/Homebrew/sorbet/rbi/gems/activesupport@6.1.7.2.rbi b/Library/Homebrew/sorbet/rbi/gems/activesupport@6.1.7.2.rbi index 5ba4ae60d8..8840430c24 100644 --- a/Library/Homebrew/sorbet/rbi/gems/activesupport@6.1.7.2.rbi +++ b/Library/Homebrew/sorbet/rbi/gems/activesupport@6.1.7.2.rbi @@ -3415,56 +3415,6 @@ class Regexp::Token < ::Struct end end -# class String -# include ::Comparable -# include ::JSON::Ext::Generator::GeneratorMethods::String -# include ::MessagePack::CoreExt -# extend ::JSON::Ext::Generator::GeneratorMethods::String::Extend - -# def acts_like_string?; end -# def as_json(options = T.unsafe(nil)); end -# def at(position); end -# def blank?; end -# def camelcase(first_letter = T.unsafe(nil)); end -# def camelize(first_letter = T.unsafe(nil)); end -# def classify; end -# def constantize; end -# def dasherize; end -# def deconstantize; end -# def demodulize; end -# def first(limit = T.unsafe(nil)); end -# def foreign_key(separate_class_name_and_id_with_underscore = T.unsafe(nil)); end -# def from(position); end -# def html_safe; end -# def humanize(capitalize: T.unsafe(nil), keep_id_suffix: T.unsafe(nil)); end -# def is_utf8?; end -# def last(limit = T.unsafe(nil)); end -# def mb_chars; end -# def parameterize(separator: T.unsafe(nil), preserve_case: T.unsafe(nil), locale: T.unsafe(nil)); end -# def pluralize(count = T.unsafe(nil), locale = T.unsafe(nil)); end -# def remove(*patterns); end -# def remove!(*patterns); end -# def safe_constantize; end -# def singularize(locale = T.unsafe(nil)); end -# def squish; end -# def squish!; end -# def tableize; end -# def titlecase(keep_id_suffix: T.unsafe(nil)); end -# def titleize(keep_id_suffix: T.unsafe(nil)); end -# def to(position); end -# def to_date; end -# def to_datetime; end -# def to_time(form = T.unsafe(nil)); end -# def truncate(truncate_at, options = T.unsafe(nil)); end -# def truncate_bytes(truncate_at, omission: T.unsafe(nil)); end -# def truncate_words(words_count, options = T.unsafe(nil)); end -# def underscore; end -# def upcase_first; end -# end - -# String::BLANK_RE = T.let(T.unsafe(nil), Regexp) -# String::ENCODED_BLANKS = T.let(T.unsafe(nil), Concurrent::Map) - class Struct include ::Enumerable diff --git a/Library/Homebrew/uninstall.rb b/Library/Homebrew/uninstall.rb index 4905e26e6e..3ecc965a6d 100644 --- a/Library/Homebrew/uninstall.rb +++ b/Library/Homebrew/uninstall.rb @@ -52,7 +52,7 @@ module Homebrew if rack.directory? versions = rack.subdirs.map(&:basename) puts <<~EOS - #{keg.name} #{versions.to_sentence} #{Utils.pluralize("", versions.count, plural: "are", singular: "is")} still installed. + #{keg.name} #{versions.to_sentence} #{versions.count == 1 ? "is" : "are"} still installed. To remove all versions, run: brew uninstall --force #{keg.name} EOS @@ -136,9 +136,8 @@ module Homebrew end def are_required_by_deps - "#{Utils.pluralize("", reqs.count, plural: "are", - singular: "is")} required by #{deps.to_sentence}, " \ - "which #{Utils.pluralize("", deps.count, plural: "are", singular: "is")} currently installed" + "#{reqs.count == 1 ? "is" : "are"} required by #{deps.to_sentence}, " \ + "which #{deps.count == 1 ? "is" : "are"} currently installed" end end @@ -158,7 +157,7 @@ module Homebrew def output ofail <<~EOS Refusing to uninstall #{reqs.to_sentence} - because #{Utils.pluralize("", reqs.count, plural: "they", singular: "it")} #{are_required_by_deps}. + because #{(reqs.count == 1) ? "it" : "they"} #{are_required_by_deps}. You can override this and force removal with: #{sample_command} EOS diff --git a/Library/Homebrew/utils/inflection.rb b/Library/Homebrew/utils/inflection.rb deleted file mode 100644 index 5aebaac58f..0000000000 --- a/Library/Homebrew/utils/inflection.rb +++ /dev/null @@ -1,52 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -module Utils - # Inflection utility methods, as a lightweight alternative to `ActiveSupport::Inflector``. - # - # @api private - module Inflection - extend T::Sig - # Removes the rightmost segment from the constant expression in the string. - # - # deconstantize('Net::HTTP') # => "Net" - # deconstantize('::Net::HTTP') # => "::Net" - # deconstantize('String') # => "" - # deconstantize('::String') # => "" - # deconstantize('') # => "" - # - # See also #demodulize. - # @see https://github.com/rails/rails/blob/b0dd7c7/activesupport/lib/active_support/inflector/methods.rb#L247-L258 - # `ActiveSupport::Inflector.deconstantize` - sig { params(path: String).returns(String) } - def self.deconstantize(path) - T.must(path[0, path.rindex("::") || 0]) # implementation based on the one in facets' Module#spacename - end - - # Removes the module part from the expression in the string. - # - # demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections" - # demodulize('Inflections') # => "Inflections" - # demodulize('::Inflections') # => "Inflections" - # demodulize('') # => "" - # - # See also #deconstantize. - # @see https://github.com/rails/rails/blob/b0dd7c7/activesupport/lib/active_support/inflector/methods.rb#L230-L245 - # `ActiveSupport::Inflector.demodulize` - sig { params(path: String).returns(String) } - def self.demodulize(path) - if (i = path.rindex("::")) - T.must(path[(i + 2)..]) - else - path - end - end - - # Combines `stem` with the `singular` or `plural` suffix based on `count`. - sig { params(stem: String, count: Integer, plural: String, singular: String).returns(String) } - def self.pluralize(stem, count, plural: "s", singular: "") - suffix = (count == 1) ? singular : plural - "#{stem}#{suffix}" - end - end -end