various: correct Style/CollectionQuerying

Signed-off-by: Patrick Linnane <patrick@linnane.io>
This commit is contained in:
Patrick Linnane 2025-07-11 10:43:00 -07:00
parent b952ec1b0b
commit cb15b67b8e
No known key found for this signature in database
8 changed files with 16 additions and 16 deletions

View File

@ -134,7 +134,7 @@ module Cask
return true if caught_exceptions.empty? return true if caught_exceptions.empty?
raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1 raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1
raise caught_exceptions.fetch(0) if caught_exceptions.count == 1 raise caught_exceptions.fetch(0) if caught_exceptions.one?
false false
end end

View File

@ -723,7 +723,7 @@ module Homebrew
all_bottle = !args.no_all_checks? && all_bottle = !args.no_all_checks? &&
(!old_bottle_spec_matches || bottle.rebuild != old_bottle_spec.rebuild) && (!old_bottle_spec_matches || bottle.rebuild != old_bottle_spec.rebuild) &&
tag_hashes.count > 1 && tag_hashes.count > 1 &&
tag_hashes.uniq { |tag_hash| "#{tag_hash["cellar"]}-#{tag_hash["sha256"]}" }.count == 1 tag_hashes.uniq { |tag_hash| "#{tag_hash["cellar"]}-#{tag_hash["sha256"]}" }.one?
old_all_bottle = old_bottle_spec.tag?(Utils::Bottles.tag(:all)) old_all_bottle = old_bottle_spec.tag?(Utils::Bottles.tag(:all))
if !all_bottle && old_all_bottle && !args.no_all_checks? if !all_bottle && old_all_bottle && !args.no_all_checks?

View File

@ -341,7 +341,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
.reject { |path| path.extname.end_with?(".incomplete") } .reject { |path| path.extname.end_with?(".incomplete") }
@cached_location = T.let( @cached_location = T.let(
if downloads.count == 1 if downloads.one?
downloads.fetch(0) downloads.fetch(0)
else else
HOMEBREW_CACHE/"downloads/#{url_sha256}--#{Utils.safe_filename(resolved_basename)}" HOMEBREW_CACHE/"downloads/#{url_sha256}--#{Utils.safe_filename(resolved_basename)}"

View File

@ -323,7 +323,7 @@ module Homebrew
end end
return unless name return unless name
if skip_hash[:messages].is_a?(Array) && skip_hash[:messages].count.positive? if skip_hash[:messages].is_a?(Array) && skip_hash[:messages].any?
# TODO: Handle multiple messages, only if needed in the future # TODO: Handle multiple messages, only if needed in the future
if skip_hash[:status] == "skipped" if skip_hash[:status] == "skipped"
puts "#{Tty.red}#{name}#{Tty.reset}: skipped - #{skip_hash[:messages][0]}" puts "#{Tty.red}#{name}#{Tty.reset}: skipped - #{skip_hash[:messages][0]}"

View File

@ -228,13 +228,13 @@ module RuboCop
rescue JSON::ParserError rescue JSON::ParserError
nil nil
end end
next if list_contents.nil? || list_contents.count.zero? next if list_contents.nil? || list_contents.none?
@tap_style_exceptions[list_name] = list_contents @tap_style_exceptions[list_name] = list_contents
end end
end end
return false if @tap_style_exceptions.nil? || @tap_style_exceptions.count.zero? return false if @tap_style_exceptions.nil? || @tap_style_exceptions.none?
return false unless @tap_style_exceptions.key? list return false unless @tap_style_exceptions.key? list
T.must(@tap_style_exceptions[list]).include?(formula || @formula_name) T.must(@tap_style_exceptions[list]).include?(formula || @formula_name)

View File

@ -176,7 +176,7 @@ module Homebrew
# Don't show the default formatter's progress dots # Don't show the default formatter's progress dots
# on CI or if only checking a single file. # on CI or if only checking a single file.
args << "--format" << "clang" if ENV["CI"] || files.count { |f| !f.directory? } == 1 args << "--format" << "clang" if ENV["CI"] || files.one? { |f| !f.directory? }
args << "--color" if Tty.color? args << "--color" if Tty.color?

View File

@ -48,7 +48,7 @@ module Homebrew
if rack.directory? if rack.directory?
versions = rack.subdirs.map(&:basename) versions = rack.subdirs.map(&:basename)
puts <<~EOS puts <<~EOS
#{keg.name} #{versions.to_sentence} #{(versions.count == 1) ? "is" : "are"} still installed. #{keg.name} #{versions.to_sentence} #{(versions.one?) ? "is" : "are"} still installed.
To remove all versions, run: To remove all versions, run:
brew uninstall --force #{keg.name} brew uninstall --force #{keg.name}
EOS EOS
@ -133,7 +133,7 @@ module Homebrew
def output def output
ofail <<~EOS ofail <<~EOS
Refusing to uninstall #{reqs.to_sentence} Refusing to uninstall #{reqs.to_sentence}
because #{(reqs.count == 1) ? "it" : "they"} #{are_required_by_deps}. because #{(reqs.one?) ? "it" : "they"} #{are_required_by_deps}.
You can override this and force removal with: You can override this and force removal with:
#{sample_command} #{sample_command}
EOS EOS
@ -146,8 +146,8 @@ module Homebrew
end end
def are_required_by_deps def are_required_by_deps
"#{(reqs.count == 1) ? "is" : "are"} required by #{deps.to_sentence}, " \ "#{(reqs.one?) ? "is" : "are"} required by #{deps.to_sentence}, " \
"which #{(deps.count == 1) ? "is" : "are"} currently installed" "which #{(deps.one?) ? "is" : "are"} currently installed"
end end
end end

View File

@ -72,17 +72,17 @@ module Homebrew
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def single_app_cask? def single_app_cask?
apps.count == 1 apps.one?
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def single_qlplugin_cask? def single_qlplugin_cask?
qlplugins.count == 1 qlplugins.one?
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def single_pkg_cask? def single_pkg_cask?
pkgs.count == 1 pkgs.one?
end end
# Filter paths to `Info.plist` files so that ones belonging # Filter paths to `Info.plist` files so that ones belonging
@ -222,14 +222,14 @@ module Homebrew
unique_info_plist_versions = unique_info_plist_versions =
top_level_info_plist_paths.filter_map { |i| BundleVersion.from_info_plist(i)&.nice_version } top_level_info_plist_paths.filter_map { |i| BundleVersion.from_info_plist(i)&.nice_version }
.uniq .uniq
return unique_info_plist_versions.first if unique_info_plist_versions.count == 1 return unique_info_plist_versions.first if unique_info_plist_versions.one?
package_info_path = extract_dir/"PackageInfo" package_info_path = extract_dir/"PackageInfo"
if package_info_path.exist? if package_info_path.exist?
if (version = BundleVersion.from_package_info(package_info_path)) if (version = BundleVersion.from_package_info(package_info_path))
return version.nice_version return version.nice_version
end end
elsif packages.count == 1 elsif packages.one?
onoe "#{pkg_path.basename} does not contain a `PackageInfo` file." onoe "#{pkg_path.basename} does not contain a `PackageInfo` file."
end end