From c86a402110078f11d4364439d8fea9d57ab7864d Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 22 Feb 2024 23:21:28 +0000 Subject: [PATCH 1/5] Fix RuboCop `Lint/RedundantDirGlobSort` offenses --- Library/.rubocop.yml | 2 -- Library/Homebrew/livecheck/livecheck.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index e825c1e09e..1d36c46984 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -462,8 +462,6 @@ Style/WordArray: MinSize: 4 # TODO: Enable these cops once https://github.com/Homebrew/brew/pull/16337#issuecomment-1855668516 is done. -Lint/RedundantDirGlobSort: - Enabled: false Naming/BlockForwarding: Enabled: false Performance/BindCall: diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 42eb080e67..ef864b7dd2 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -83,7 +83,7 @@ module Homebrew other_taps.each_value do |tap| tap_strategy_path = "#{tap.path}/livecheck/strategy" - Dir["#{tap_strategy_path}/*.rb"].sort.each { require(_1) } if Dir.exist?(tap_strategy_path) + Dir["#{tap_strategy_path}/*.rb"].each { require(_1) } if Dir.exist?(tap_strategy_path) end end From f4218a6316678f443be8757695e80d48c6661764 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 22 Feb 2024 23:29:55 +0000 Subject: [PATCH 2/5] Fix RuboCop `Performance/MapCompact` offenses - Rename an iterator variable since it would make the line too long. --- Library/.rubocop.yml | 2 -- .../cask/artifact/abstract_uninstall.rb | 4 +-- Library/Homebrew/cask/cask.rb | 4 +-- Library/Homebrew/cask/cask_loader.rb | 3 +- Library/Homebrew/cask/caskroom.rb | 4 +-- Library/Homebrew/cask/dsl.rb | 3 +- Library/Homebrew/caveats.rb | 4 +-- Library/Homebrew/cli/parser.rb | 16 +++++----- Library/Homebrew/cmd/--prefix.rb | 4 +-- Library/Homebrew/cmd/link.rb | 4 +-- Library/Homebrew/cmd/untap.rb | 8 ++--- Library/Homebrew/cmd/update-report.rb | 16 +++++----- Library/Homebrew/commands.rb | 4 +-- Library/Homebrew/completions.rb | 32 +++++++++---------- Library/Homebrew/dev-cmd/bottle.rb | 4 +-- Library/Homebrew/dev-cmd/contributions.rb | 4 +-- Library/Homebrew/dev-cmd/extract.rb | 4 +-- Library/Homebrew/dev-cmd/linkage.rb | 2 +- Library/Homebrew/dev-cmd/pr-pull.rb | 8 ++--- Library/Homebrew/dev-cmd/release.rb | 4 +-- Library/Homebrew/dev-cmd/tests.rb | 4 +-- Library/Homebrew/dev-cmd/unbottled.rb | 4 +-- Library/Homebrew/diagnostic.rb | 8 ++--- Library/Homebrew/download_strategy.rb | 4 +-- Library/Homebrew/extend/kernel.rb | 4 +-- .../extend/os/linux/extend/ENV/super.rb | 4 +-- .../extend/os/mac/unpack_strategy/zip.rb | 3 +- Library/Homebrew/formula.rb | 22 ++++++------- Library/Homebrew/formula_auditor.rb | 2 +- Library/Homebrew/formula_cellar_checks.rb | 7 ++-- Library/Homebrew/formulary.rb | 4 +-- Library/Homebrew/global.rb | 4 +-- Library/Homebrew/install.rb | 4 +-- Library/Homebrew/installed_dependents.rb | 4 +-- Library/Homebrew/language/python.rb | 4 +-- .../livecheck/strategy/extract_plist.rb | 4 +-- Library/Homebrew/livecheck/strategy/git.rb | 4 +-- .../livecheck/strategy/github_releases.rb | 4 +-- .../livecheck/strategy/header_match.rb | 4 +-- .../Homebrew/livecheck/strategy/page_match.rb | 4 +-- .../Homebrew/livecheck/strategy/sparkle.rb | 4 +-- Library/Homebrew/manpages.rb | 4 +-- Library/Homebrew/os/linux/elf.rb | 4 +-- .../rubocops/cask/array_alphabetization.rb | 4 +-- Library/Homebrew/rubocops/components_order.rb | 4 +-- Library/Homebrew/search.rb | 8 ++--- Library/Homebrew/software_spec.rb | 6 ++-- .../Homebrew/test/diagnostic_checks_spec.rb | 2 +- Library/Homebrew/unlink.rb | 3 +- Library/Homebrew/unpack_strategy/dmg.rb | 6 ++-- Library/Homebrew/unversioned_cask_checker.rb | 4 +-- Library/Homebrew/upgrade.rb | 4 +-- Library/Homebrew/utils/github.rb | 4 +-- Library/Homebrew/utils/pypi.rb | 4 +-- Library/Homebrew/utils/spdx.rb | 4 +-- Library/Homebrew/utils/topological_hash.rb | 3 +- 56 files changed, 146 insertions(+), 158 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 1d36c46984..67087e5db6 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -466,8 +466,6 @@ Naming/BlockForwarding: Enabled: false Performance/BindCall: Enabled: false -Performance/MapCompact: - Enabled: false Style/ArgumentsForwarding: Enabled: false Style/HashSyntax: diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 61af5bd458..66a6f2dabc 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -169,10 +169,10 @@ module Cask regex = Regexp.escape(search).gsub("\\*", ".*") system_command!("/bin/launchctl", args: ["list"]) .stdout.lines.drop(1) # skip stdout column headers - .map do |line| + .filter_map do |line| pid, _state, id = line.chomp.split(/\s+/) id if pid.to_i.nonzero? && id.match?(regex) - end.compact + end end sig { returns(String) } diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 1a9b2d1bde..a98609d7b8 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -33,13 +33,13 @@ module Cask # Load core casks from tokens so they load from the API when the core cask is not tapped. tokens_and_files = CoreCaskTap.instance.cask_tokens tokens_and_files += Tap.reject(&:core_cask_tap?).flat_map(&:cask_files) - tokens_and_files.map do |token_or_file| + tokens_and_files.filter_map do |token_or_file| CaskLoader.load(token_or_file) rescue CaskUnreadableError => e opoo e.message nil - end.compact + end end def tap diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index fce987841e..ae96d65574 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -469,8 +469,7 @@ module Cask token = ref - loaders = Tap.map { |tap| super("#{tap}/#{token}", warn: warn) } - .compact + loaders = Tap.filter_map { |tap| super("#{tap}/#{token}", warn: warn) } .select { _1.path.exist? } case loaders.count diff --git a/Library/Homebrew/cask/caskroom.rb b/Library/Homebrew/cask/caskroom.rb index 9a6f7bab33..75605f0d99 100644 --- a/Library/Homebrew/cask/caskroom.rb +++ b/Library/Homebrew/cask/caskroom.rb @@ -52,14 +52,14 @@ module Cask sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) } def self.casks(config: nil) - tokens.sort.map do |token| + tokens.sort.filter_map do |token| CaskLoader.load(token, config: config, warn: false) rescue TapCaskAmbiguityError => e T.must(e.loaders.first).load(config: config) rescue # Don't blow up because of a single unavailable cask. nil - end.compact + end end end end diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index d139d90b5b..75d7e4b1dc 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -180,12 +180,11 @@ module Cask raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil? locales = cask.config.languages - .map do |language| + .filter_map do |language| Locale.parse(language) rescue Locale::ParserError nil end - .compact locales.each do |locale| key = locale.detect(@language_blocks.keys) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 1a7469e8c8..c2fe663de6 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -102,11 +102,11 @@ class Caveats private def keg - @keg ||= [formula.prefix, formula.opt_prefix, formula.linked_keg].map do |d| + @keg ||= [formula.prefix, formula.opt_prefix, formula.linked_keg].filter_map do |d| Keg.new(d.resolved_path) rescue nil - end.compact.first + end.first end def function_completion_caveats(shell) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index eebc6c5bc0..ca51b66111 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -447,11 +447,11 @@ module Homebrew def generate_usage_banner command_names = ["`#{@command_name}`"] aliases_to_skip = %w[instal uninstal] - command_names += Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.map do |command_alias, command| + command_names += Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.filter_map do |command_alias, command| next if aliases_to_skip.include? command_alias "`#{command_alias}`" if command == @command_name - end.compact.sort + end.sort options = if @non_global_processed_options.empty? "" @@ -469,12 +469,12 @@ module Homebrew named_args = "" if @named_args_type.present? && @named_args_type != :none arg_type = if @named_args_type.is_a? Array - types = @named_args_type.map do |type| + types = @named_args_type.filter_map do |type| next unless type.is_a? Symbol next SYMBOL_TO_USAGE_MAPPING[type] if SYMBOL_TO_USAGE_MAPPING.key?(type) "<#{type}>" - end.compact + end types << "" if @named_args_type.any?(String) types.join("|") elsif SYMBOL_TO_USAGE_MAPPING.key? @named_args_type @@ -593,11 +593,11 @@ module Homebrew end def check_named_args(args) - types = Array(@named_args_type).map do |type| + types = Array(@named_args_type).filter_map do |type| next type if type.is_a? Symbol :subcommand - end.compact.uniq + end.uniq exception = if @min_named_args && @max_named_args && @min_named_args == @max_named_args && args.size != @max_named_args @@ -650,7 +650,7 @@ module Homebrew end # Only lowercase names, not paths, bottle filenames or URLs - named_args.map do |arg| + named_args.filter_map do |arg| next if arg.match?(HOMEBREW_CASK_TAP_CASK_REGEX) begin @@ -658,7 +658,7 @@ module Homebrew rescue FormulaUnavailableError, FormulaSpecificationError nil end - end.compact.uniq(&:name) + end.uniq(&:name) end def only_casks?(argv) diff --git a/Library/Homebrew/cmd/--prefix.rb b/Library/Homebrew/cmd/--prefix.rb index 71282fcba3..0a39c8f9b4 100644 --- a/Library/Homebrew/cmd/--prefix.rb +++ b/Library/Homebrew/cmd/--prefix.rb @@ -39,12 +39,12 @@ module Homebrew puts HOMEBREW_PREFIX else formulae = args.named.to_resolved_formulae - prefixes = formulae.map do |f| + prefixes = formulae.filter_map do |f| next nil if args.installed? && !f.opt_prefix.exist? # this case will be short-circuited by brew.sh logic for a single formula f.opt_prefix - end.compact + end puts prefixes if args.installed? missing_formulae = formulae.reject(&:optlinked?) diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 78e829662d..8e63c1a0ba 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -40,7 +40,7 @@ module Homebrew } kegs = if args.HEAD? - args.named.to_kegs.group_by(&:name).map do |name, resolved_kegs| + args.named.to_kegs.group_by(&:name).filter_map do |name, resolved_kegs| head_keg = resolved_kegs.find { |keg| keg.version.head? } next head_keg if head_keg.present? @@ -49,7 +49,7 @@ module Homebrew To install, run: brew install --HEAD #{name} EOS - end.compact + end else args.named.to_latest_kegs end diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index 030bdcce81..90696f7f55 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -28,7 +28,7 @@ module Homebrew if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && !tap.core_cask_tap?) installed_formula_names = T.let(nil, T.nilable(T::Set[String])) - installed_tap_formulae = tap.formula_names.map do |formula_name| + installed_tap_formulae = tap.formula_names.filter_map do |formula_name| # initialise lazily in case there's no formulae in this tap installed_formula_names ||= Set.new(Formula.installed_formula_names) next unless installed_formula_names.include?(formula_name) @@ -43,10 +43,10 @@ module Homebrew # Can't use Formula#any_version_installed? because it doesn't consider # taps correctly. formula if formula.installed_kegs.any? { |keg| keg.tab.tap == tap } - end.compact + end installed_cask_tokens = T.let(nil, T.nilable(T::Set[String])) - installed_tap_casks = tap.cask_tokens.map do |cask_token| + installed_tap_casks = tap.cask_tokens.filter_map do |cask_token| # initialise lazily in case there's no casks in this tap installed_cask_tokens ||= Set.new(Cask::Caskroom.tokens) next unless installed_cask_tokens.include?(cask_token) @@ -59,7 +59,7 @@ module Homebrew end cask if cask.installed? - end.compact + end if installed_tap_formulae.present? || installed_tap_casks.present? installed_names = (installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n") diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index a951eafb38..cbe68a2496 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -711,7 +711,7 @@ class Reporter header_regex = /^(---|\+\+\+) / add_delete_characters = ["+", "-"].freeze - diff_output.lines.map do |line| + diff_output.lines.filter_map do |line| next if line.match?(header_regex) next unless add_delete_characters.include?(line[0]) @@ -719,7 +719,7 @@ class Reporter .sub(/^-/, "D #{api_dir_prefix.basename}/") .sub(/$/, ".rb") .chomp - end.compact.join("\n") + end.join("\n") else Utils.popen_read( "git", "-C", tap.path, "diff-tree", "-r", "--name-status", "--diff-filter=AMDR", @@ -845,9 +845,9 @@ class ReporterHub end def dump_new_cask_report - casks = select_formula_or_cask(:AC).sort.map do |name| + casks = select_formula_or_cask(:AC).sort.filter_map do |name| name.split("/").last unless cask_installed?(name) - end.compact + end output_dump_formula_or_cask_report "New Casks", casks end @@ -873,13 +873,13 @@ class ReporterHub end def dump_deleted_formula_report(report_all) - formulae = select_formula_or_cask(:D).sort.map do |name| + formulae = select_formula_or_cask(:D).sort.filter_map do |name| if installed?(name) pretty_uninstalled(name) elsif report_all name end - end.compact + end title = if report_all "Deleted Formulae" @@ -890,14 +890,14 @@ class ReporterHub end def dump_deleted_cask_report(report_all) - casks = select_formula_or_cask(:DC).sort.map do |name| + casks = select_formula_or_cask(:DC).sort.filter_map do |name| name = name.split("/").last if cask_installed?(name) pretty_uninstalled(name) elsif report_all name end - end.compact + end title = if report_all "Deleted Casks" diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 9d8c5bb9c0..7d490c31e7 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -182,11 +182,11 @@ module Commands return if path.blank? if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path)) - cmd_parser.processed_options.map do |short, long, _, desc, hidden| + cmd_parser.processed_options.filter_map do |short, long, _, desc, hidden| next if hidden [long || short, desc] - end.compact + end else options = [] comment_lines = path.read.lines.grep(/^#:/) diff --git a/Library/Homebrew/completions.rb b/Library/Homebrew/completions.rb index 063e4eaafd..4e60b8209a 100644 --- a/Library/Homebrew/completions.rb +++ b/Library/Homebrew/completions.rb @@ -200,14 +200,14 @@ module Homebrew sig { params(commands: T::Array[String]).returns(String) } def self.generate_bash_completion_file(commands) variables = Variables.new( - completion_functions: commands.map do |command| + completion_functions: commands.filter_map do |command| generate_bash_subcommand_completion command - end.compact, - function_mappings: commands.map do |command| + end, + function_mappings: commands.filter_map do |command| next unless command_gets_completions? command "#{command}) _brew_#{Commands.method_name command} ;;" - end.compact, + end, ) ERB.new((TEMPLATE_DIR/"bash.erb").read, trim_mode: ">").result(variables.instance_eval { binding }) @@ -276,13 +276,13 @@ module Homebrew sig { params(commands: T::Array[String]).returns(String) } def self.generate_zsh_completion_file(commands) variables = Variables.new( - aliases: Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.map do |alias_command, command| - alias_command = "'#{alias_command}'" if alias_command.start_with? "-" + aliases: Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.filter_map do |alias_cmd, command| + alias_cmd = "'#{alias_cmd}'" if alias_cmd.start_with? "-" command = "'#{command}'" if command.start_with? "-" - "#{alias_command} #{command}" - end.compact, + "#{alias_cmd} #{command}" + end, - builtin_command_descriptions: commands.map do |command| + builtin_command_descriptions: commands.filter_map do |command| next if Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.key? command description = Commands.command_description(command, short: true) @@ -290,11 +290,11 @@ module Homebrew description = format_description description "'#{command}:#{description}'" - end.compact, + end, - completion_functions: commands.map do |command| + completion_functions: commands.filter_map do |command| generate_zsh_subcommand_completion command - end.compact, + end, ) ERB.new((TEMPLATE_DIR/"zsh.erb").read, trim_mode: ">").result(variables.instance_eval { binding }) @@ -307,11 +307,11 @@ module Homebrew command_description = format_description Commands.command_description(command, short: true), fish: true lines = ["__fish_brew_complete_cmd '#{command}' '#{command_description}'"] - options = command_options(command).sort.map do |opt, desc| + options = command_options(command).sort.filter_map do |opt, desc| arg_line = "__fish_brew_complete_arg '#{command}' -l #{opt.sub(/^-+/, "")}" arg_line += " -d '#{format_description desc, fish: true}'" if desc.present? arg_line - end.compact + end subcommands = [] named_args = [] @@ -350,9 +350,9 @@ module Homebrew sig { params(commands: T::Array[String]).returns(String) } def self.generate_fish_completion_file(commands) variables = Variables.new( - completion_functions: commands.map do |command| + completion_functions: commands.filter_map do |command| generate_fish_subcommand_completion command - end.compact, + end, ) ERB.new((TEMPLATE_DIR/"fish.erb").read, trim_mode: ">").result(variables.instance_eval { binding }) diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 0204380b8f..24469cc7de 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -199,7 +199,7 @@ module Homebrew end def self.bottle_output(bottle, root_url_using) - cellars = bottle.checksums.map do |checksum| + cellars = bottle.checksums.filter_map do |checksum| cellar = checksum["cellar"] next unless cellar_parameter_needed? cellar @@ -209,7 +209,7 @@ module Homebrew when Symbol ":#{cellar}" end - end.compact + end tag_column = cellars.empty? ? 0 : "cellar: #{cellars.max_by(&:length)}, ".length tags = bottle.checksums.map { |checksum| checksum["tag"] } diff --git a/Library/Homebrew/dev-cmd/contributions.rb b/Library/Homebrew/dev-cmd/contributions.rb index b38fdc7419..c05cf2726d 100755 --- a/Library/Homebrew/dev-cmd/contributions.rb +++ b/Library/Homebrew/dev-cmd/contributions.rb @@ -74,12 +74,12 @@ module Homebrew results[username] = scan_repositories(repos, username, args, from: from) grand_totals[username] = total(results[username]) - contributions = contribution_types.map do |type| + contributions = contribution_types.filter_map do |type| type_count = grand_totals[username][type] next if type_count.to_i.zero? "#{Utils.pluralize("time", type_count, include_count: true)} (#{type})" - end.compact + end contributions << "#{Utils.pluralize("time", grand_totals[username].values.sum, include_count: true)} (total)" puts [ diff --git a/Library/Homebrew/dev-cmd/extract.rb b/Library/Homebrew/dev-cmd/extract.rb index 2f3291d5f3..257cd30450 100644 --- a/Library/Homebrew/dev-cmd/extract.rb +++ b/Library/Homebrew/dev-cmd/extract.rb @@ -102,9 +102,9 @@ module Homebrew odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil? else # Search in the root directory of as well as recursively in all of its subdirectories - files = Dir[repo/"{,**/}"].map do |dir| + files = Dir[repo/"{,**/}"].filter_map do |dir| Pathname.glob("#{dir}/#{name}.rb").find(&:file?) - end.compact + end if files.empty? ohai "Searching repository history" diff --git a/Library/Homebrew/dev-cmd/linkage.rb b/Library/Homebrew/dev-cmd/linkage.rb index 1eee527d66..753106f67a 100644 --- a/Library/Homebrew/dev-cmd/linkage.rb +++ b/Library/Homebrew/dev-cmd/linkage.rb @@ -37,7 +37,7 @@ module Homebrew CacheStoreDatabase.use(:linkage) do |db| kegs = if args.named.to_default_kegs.empty? - Formula.installed.map(&:any_installed_keg).compact + Formula.installed.filter_map(&:any_installed_keg) else args.named.to_default_kegs end diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 6827f92ce6..009d4241f5 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -329,7 +329,7 @@ module Homebrew "-r", "--name-only", "--diff-filter=AM", original_commit, "HEAD", "--", tap.formula_dir) .lines - .map do |line| + .filter_map do |line| next unless line.end_with? ".rb\n" name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}" @@ -342,12 +342,12 @@ module Homebrew rescue FormulaUnavailableError nil end - end.compact + end casks = Utils.popen_read("git", "-C", tap.path, "diff-tree", "-r", "--name-only", "--diff-filter=AM", original_commit, "HEAD", "--", tap.cask_dir) .lines - .map do |line| + .filter_map do |line| next unless line.end_with? ".rb\n" name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}" @@ -356,7 +356,7 @@ module Homebrew rescue Cask::CaskUnavailableError nil end - end.compact + end formulae + casks end diff --git a/Library/Homebrew/dev-cmd/release.rb b/Library/Homebrew/dev-cmd/release.rb index 923b66d1df..ec6e46a414 100755 --- a/Library/Homebrew/dev-cmd/release.rb +++ b/Library/Homebrew/dev-cmd/release.rb @@ -70,11 +70,11 @@ module Homebrew # release notes without usernames, new contributors, or extra lines blog_post_notes = GitHub.generate_release_notes("Homebrew", "brew", new_version, previous_tag: latest_major_minor_version)["body"] - blog_post_notes = blog_post_notes.lines.map do |line| + blog_post_notes = blog_post_notes.lines.filter_map do |line| next unless (match = line.match(/^\* (.*) by @[\w-]+ in (.*)$/)) "- [#{match[1]}](#{match[2]})" - end.compact.sort + end.sort puts blog_post_notes end diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 06551b3142..005764c3cc 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -77,7 +77,7 @@ module Homebrew raise UsageError, "No files have been changed from the master branch!" if changed_files.blank? filestub_regex = %r{Library/Homebrew/([\w/-]+).rb} - changed_files.scan(filestub_regex).map(&:last).map do |filestub| + changed_files.scan(filestub_regex).map(&:last).filter_map do |filestub| if filestub.start_with?("test/") # Only run tests on *_spec.rb files in test/ folder filestub.end_with?("_spec") ? Pathname("#{filestub}.rb") : nil @@ -85,7 +85,7 @@ module Homebrew # For all other changed .rb files guess the associated test file name Pathname("test/#{filestub}_spec.rb") end - end.compact.select(&:exist?) + end.select(&:exist?) end def self.tests diff --git a/Library/Homebrew/dev-cmd/unbottled.rb b/Library/Homebrew/dev-cmd/unbottled.rb index e4245a80a1..33b56d2b3c 100644 --- a/Library/Homebrew/dev-cmd/unbottled.rb +++ b/Library/Homebrew/dev-cmd/unbottled.rb @@ -133,7 +133,7 @@ module Homebrew "`HOMEBREW_NO_GITHUB_API` and `HOMEBREW_NO_ANALYTICS` to be unset" end - formulae = analytics["items"].map do |i| + formulae = analytics["items"].filter_map do |i| f = i["formula"].split.first next if f.include?("/") next if formula_installs[f].present? @@ -144,7 +144,7 @@ module Homebrew rescue FormulaUnavailableError nil end - end.compact + end @sort = " (sorted by installs in the last 90 days; top 10,000 only)" all_formulae = Formula.all(eval_all: args.eval_all?) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 23f1b53e22..244c935383 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -545,11 +545,11 @@ module Homebrew return if ENV["CI"] return unless Utils::Git.available? - commands = Tap.select(&:installed?).map do |tap| + commands = Tap.select(&:installed?).filter_map do |tap| next if tap.git_repo.default_origin_branch? "git -C $(brew --repo #{tap.name}) checkout #{tap.git_repo.origin_branch_name}" - end.compact + end return if commands.blank? @@ -833,7 +833,7 @@ module Homebrew def check_deleted_formula kegs = Keg.all - deleted_formulae = kegs.map do |keg| + deleted_formulae = kegs.filter_map do |keg| tap = Tab.for_keg(keg).tap loadable = [ @@ -858,7 +858,7 @@ module Homebrew end keg.name unless loadable - end.compact.uniq + end.uniq return if deleted_formulae.blank? diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index cb364c2441..e98ca84d63 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -354,9 +354,9 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy end if (uri_path = uri.path.presence) - components[:path] = uri_path.split("/").map do |part| + components[:path] = uri_path.split("/").filter_map do |part| URI::DEFAULT_PARSER.unescape(part).presence - end.compact + end end if search_query && (uri_query = uri.query.presence) diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index c29d1f1296..8de3f244da 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -267,7 +267,7 @@ module Kernel end def which_all(cmd, path = ENV.fetch("PATH")) - PATH.new(path).map do |p| + PATH.new(path).filter_map do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -276,7 +276,7 @@ module Kernel next end Pathname.new(pcmd) if File.file?(pcmd) && File.executable?(pcmd) - end.compact.uniq + end.uniq end def which_editor(silent: false) diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 2f151597d5..2bfe76d6f3 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -25,12 +25,12 @@ module Superenv def homebrew_extra_paths paths = generic_homebrew_extra_paths - paths += %w[binutils make].map do |f| + paths += %w[binutils make].filter_map do |f| bin = Formulary.factory(f).opt_bin bin if bin.directory? rescue FormulaUnavailableError nil - end.compact + end paths end diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index 370b2a21d9..5063370545 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -36,8 +36,7 @@ module UnpackStrategy volumes = result.stderr.chomp .split("\n") - .map { |l| l[/\A skipping: (.+) volume label\Z/, 1] } - .compact + .filter_map { |l| l[/\A skipping: (.+) volume label\Z/, 1] } return if volumes.empty? diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9dd88c0365..f2b683c756 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -518,11 +518,11 @@ class Formula # Returns any `@`-versioned Formula objects for any Formula (including versioned formulae). sig { returns(T::Array[Formula]) } def versioned_formulae - versioned_formulae_names.map do |name| + versioned_formulae_names.filter_map do |name| Formula[name] rescue FormulaUnavailableError nil - end.compact.sort_by(&:version).reverse + end.sort_by(&:version).reverse end # A named {Resource} for the currently active {SoftwareSpec}. @@ -631,10 +631,10 @@ class Formula end def latest_head_version - head_versions = installed_prefixes.map do |pn| + head_versions = installed_prefixes.filter_map do |pn| pn_pkgversion = PkgVersion.parse(pn.basename.to_s) pn_pkgversion if pn_pkgversion.head? - end.compact + end head_versions.max_by do |pn_pkgversion| [Tab.for_keg(prefix(pn_pkgversion)).source_modified_time, pn_pkgversion.revision] @@ -1934,7 +1934,7 @@ class Formula raise ArgumentError, "Formula#all without `--eval-all` or HOMEBREW_EVAL_ALL" end - (core_names + tap_files).map do |name_or_file| + (core_names + tap_files).filter_map do |name_or_file| Formulary.factory(name_or_file) rescue FormulaUnavailableError, FormulaUnreadableError => e # Don't let one broken formula break commands. But do complain. @@ -1942,7 +1942,7 @@ class Formula $stderr.puts e nil - end.compact + end end # An array of all racks currently installed. @@ -2108,12 +2108,12 @@ class Formula def runtime_dependencies(read_from_tab: true, undeclared: true) deps = if read_from_tab && undeclared && (tab_deps = any_installed_keg&.runtime_dependencies) - tab_deps.map do |d| + tab_deps.filter_map do |d| full_name = d["full_name"] next unless full_name Dependency.new full_name - end.compact + end end begin deps ||= declared_runtime_dependencies unless undeclared @@ -2134,11 +2134,11 @@ class Formula Formula.cache[:runtime_formula_dependencies][cache_key] ||= runtime_dependencies( read_from_tab: read_from_tab, undeclared: undeclared, - ).map do |d| + ).filter_map do |d| d.to_formula rescue FormulaUnavailableError nil - end.compact + end end def runtime_installed_formula_dependents @@ -2192,7 +2192,7 @@ class Formula { dependable: dependable, # Now find the list of specs each dependency was a part of. - specs: dependables.map { |spec, spec_deps| spec if spec_deps&.include?(dependable) }.compact, + specs: dependables.filter_map { |spec, spec_deps| spec if spec_deps&.include?(dependable) }, } end end diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index b094171b22..d44cbd0e12 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -33,7 +33,7 @@ module Homebrew @problems = [] @new_formula_problems = [] @text = FormulaTextAuditor.new(formula.path) - @specs = %w[stable head].map { |s| formula.send(s) }.compact + @specs = %w[stable head].filter_map { |s| formula.send(s) } @spdx_license_data = options[:spdx_license_data] @spdx_exception_data = options[:spdx_exception_data] @tap_audit = options[:tap_audit] diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index a2bac0c487..79738cfea1 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -188,20 +188,19 @@ module FormulaCellarChecks .select(&:directory?) .map(&:basename) - pythons = lib_subdirs.map do |p| + pythons = lib_subdirs.filter_map do |p| match = p.to_s.match(/^python(\d+\.\d+)$/) next if match.blank? next if match.captures.blank? match.captures.first - end.compact + end return if pythons.blank? python_deps = deps.map(&:name) .grep(/^python(@.*)?$/) - .map { |d| Formula[d].version.to_s[/^\d+\.\d+/] } - .compact + .filter_map { |d| Formula[d].version.to_s[/^\d+\.\d+/] } return if python_deps.blank? return if pythons.any? { |v| python_deps.include? v } diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 0e7dcfdea7..41e443fe63 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -779,9 +779,7 @@ module Formulary name = ref - loaders = Tap.map { |tap| super("#{tap}/#{name}", warn: warn) } - .compact - .select { _1.path.exist? } + loaders = Tap.filter_map { |tap| super("#{tap}/#{name}", warn: warn) }.select { _1.path.exist? } case loaders.count when 1 diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index f843a6a6b7..c136088bb3 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -132,11 +132,11 @@ require "cli/args" require "PATH" ENV["HOMEBREW_PATH"] ||= ENV.fetch("PATH") -ORIGINAL_PATHS = PATH.new(ENV.fetch("HOMEBREW_PATH")).map do |p| +ORIGINAL_PATHS = PATH.new(ENV.fetch("HOMEBREW_PATH")).filter_map do |p| Pathname.new(p).expand_path rescue nil -end.compact.freeze +end.freeze require "exceptions" require "utils" diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index f81f6e38fe..efc67360e5 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -244,7 +244,7 @@ module Homebrew dry_run: false, skip_post_install: false ) - formula_installers = formulae_to_install.map do |formula| + formula_installers = formulae_to_install.filter_map do |formula| Migrator.migrate_if_needed(formula, force: force, dry_run: dry_run) build_options = formula.build @@ -284,7 +284,7 @@ module Homebrew ofail "#{formula}: #{e}" nil end - end.compact + end if dry_run if (formulae_name_to_install = formulae_to_install.map(&:name)) diff --git a/Library/Homebrew/installed_dependents.rb b/Library/Homebrew/installed_dependents.rb index 1b0a188ce5..afd7bf2418 100644 --- a/Library/Homebrew/installed_dependents.rb +++ b/Library/Homebrew/installed_dependents.rb @@ -52,12 +52,12 @@ module InstalledDependents CaskDependent.new(dependent).runtime_dependencies.map(&:to_formula) end - required_kegs = required.map do |f| + required_kegs = required.filter_map do |f| f_kegs = kegs_by_source[[f.name, f.tap]] next unless f_kegs f_kegs.max_by(&:version) - end.compact + end next if required_kegs.empty? diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index c289b0e324..5887cc6ab2 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -158,7 +158,7 @@ module Language # Find any Python bindings provided by recursive dependencies formula_deps = formula.recursive_dependencies - pth_contents = formula_deps.map do |d| + pth_contents = formula_deps.filter_map do |d| next if d.build? || d.test? # Do not add the main site-package provided by the brewed # Python formula, to keep the virtual-env's site-package pristine @@ -168,7 +168,7 @@ module Language next unless dep_site_packages.exist? "import site; site.addsitedir('#{dep_site_packages}')\n" - end.compact + end unless pth_contents.empty? (venv_root/Language::Python.site_packages(python)/"homebrew_deps.pth").write pth_contents.join end diff --git a/Library/Homebrew/livecheck/strategy/extract_plist.rb b/Library/Homebrew/livecheck/strategy/extract_plist.rb index 1e348f7215..489b8ffdf6 100644 --- a/Library/Homebrew/livecheck/strategy/extract_plist.rb +++ b/Library/Homebrew/livecheck/strategy/extract_plist.rb @@ -69,9 +69,9 @@ module Homebrew return Strategy.handle_block_return(block_return_value) end - items.map do |_key, item| + items.filter_map do |_key, item| item.bundle_version.nice_version - end.compact.uniq + end.uniq end # Uses {UnversionedCaskChecker} on the provided cask to identify diff --git a/Library/Homebrew/livecheck/strategy/git.rb b/Library/Homebrew/livecheck/strategy/git.rb index 8414baca23..2b2ef95f13 100644 --- a/Library/Homebrew/livecheck/strategy/git.rb +++ b/Library/Homebrew/livecheck/strategy/git.rb @@ -101,7 +101,7 @@ module Homebrew return Strategy.handle_block_return(block_return_value) end - tags.map do |tag| + tags.filter_map do |tag| if regex # Use the first capture group (the version) # This code is not typesafe unless the regex includes a capture group @@ -111,7 +111,7 @@ module Homebrew # version text tag[DEFAULT_REGEX, 1] end - end.compact.uniq + end.uniq end # Checks the Git tags for new versions. When a regex isn't provided, diff --git a/Library/Homebrew/livecheck/strategy/github_releases.rb b/Library/Homebrew/livecheck/strategy/github_releases.rb index 1d4300cf15..0777884558 100644 --- a/Library/Homebrew/livecheck/strategy/github_releases.rb +++ b/Library/Homebrew/livecheck/strategy/github_releases.rb @@ -105,7 +105,7 @@ module Homebrew end content = [content] unless content.is_a?(Array) - content.compact_blank.map do |release| + content.compact_blank.filter_map do |release| next if release["draft"] || release["prerelease"] value = T.let(nil, T.untyped) @@ -116,7 +116,7 @@ module Homebrew value = match[1] end value - end.compact.uniq + end.uniq end # Generates the GitHub API URL for the repository's recent releases diff --git a/Library/Homebrew/livecheck/strategy/header_match.rb b/Library/Homebrew/livecheck/strategy/header_match.rb index 9af862fa82..db83207a9c 100644 --- a/Library/Homebrew/livecheck/strategy/header_match.rb +++ b/Library/Homebrew/livecheck/strategy/header_match.rb @@ -51,7 +51,7 @@ module Homebrew return Strategy.handle_block_return(block_return_value) end - DEFAULT_HEADERS_TO_CHECK.map do |header_name| + DEFAULT_HEADERS_TO_CHECK.filter_map do |header_name| header_value = headers[header_name] next if header_value.blank? @@ -61,7 +61,7 @@ module Homebrew v = Version.parse(header_value, detected_from_url: true) v.null? ? nil : v.to_s end - end.compact.uniq + end.uniq end # Checks the final URL for new versions after following all redirections, diff --git a/Library/Homebrew/livecheck/strategy/page_match.rb b/Library/Homebrew/livecheck/strategy/page_match.rb index 821119d810..51f4211cf0 100644 --- a/Library/Homebrew/livecheck/strategy/page_match.rb +++ b/Library/Homebrew/livecheck/strategy/page_match.rb @@ -60,14 +60,14 @@ module Homebrew return [] if regex.blank? - content.scan(regex).map do |match| + content.scan(regex).filter_map do |match| case match when String match when Array match.first end - end.compact.uniq + end.uniq end # Checks the content at the URL for new versions, using the provided diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index dcfaf2f973..6b539b29dd 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -85,7 +85,7 @@ module Homebrew end end - xml.get_elements("//rss//channel//item").map do |item| + xml.get_elements("//rss//channel//item").filter_map do |item| enclosure = item.elements["enclosure"] if enclosure @@ -144,7 +144,7 @@ module Homebrew data[:pub_date] ||= Time.new(0) Item.new(**data) - end.compact + end end # Filters out items that aren't suitable for Homebrew. diff --git a/Library/Homebrew/manpages.rb b/Library/Homebrew/manpages.rb index cdfa36bce7..cac8e2d5d8 100644 --- a/Library/Homebrew/manpages.rb +++ b/Library/Homebrew/manpages.rb @@ -140,7 +140,7 @@ module Homebrew def self.cmd_parser_manpage_lines(cmd_parser) lines = [format_usage_banner(cmd_parser.usage_banner_text)] - lines += cmd_parser.processed_options.map do |short, long, _, desc, hidden| + lines += cmd_parser.processed_options.filter_map do |short, long, _, desc, hidden| next if hidden if long.present? @@ -151,7 +151,7 @@ module Homebrew end generate_option_doc(short, long, desc) - end.compact + end lines end diff --git a/Library/Homebrew/os/linux/elf.rb b/Library/Homebrew/os/linux/elf.rb index 1e1215946a..efd855db95 100644 --- a/Library/Homebrew/os/linux/elf.rb +++ b/Library/Homebrew/os/linux/elf.rb @@ -134,12 +134,12 @@ module ELFShim ldd_output = Utils.popen_read(ldd, path.expand_path.to_s).split("\n") return unless $CHILD_STATUS.success? - ldd_paths = ldd_output.map do |line| + ldd_paths = ldd_output.filter_map do |line| match = line.match(/\t.+ => (.+) \(.+\)|\t(.+) => not found/) next unless match match.captures.compact.first - end.compact + end @dylibs = ldd_paths.select do |ldd_path| needed.include? File.basename(ldd_path) end diff --git a/Library/Homebrew/rubocops/cask/array_alphabetization.rb b/Library/Homebrew/rubocops/cask/array_alphabetization.rb index d6ca7f3ca3..39f7b618b9 100644 --- a/Library/Homebrew/rubocops/cask/array_alphabetization.rb +++ b/Library/Homebrew/rubocops/cask/array_alphabetization.rb @@ -36,11 +36,11 @@ module RuboCop def sort_array(source) # Combine each comment with the line(s) below so that they remain in the same relative location - combined_source = source.each_with_index.map do |line, index| + combined_source = source.each_with_index.filter_map do |line, index| next if line.strip.start_with?("#") next recursively_find_comments(source, index, line) - end.compact + end # Separate the lines into those that should be sorted and those that should not # ie. skip the opening and closing brackets of the array diff --git a/Library/Homebrew/rubocops/components_order.rb b/Library/Homebrew/rubocops/components_order.rb index c7ac428903..50c0949a47 100644 --- a/Library/Homebrew/rubocops/components_order.rb +++ b/Library/Homebrew/rubocops/components_order.rb @@ -89,13 +89,13 @@ module RuboCop method_name = on_system_block.method_name child_nodes = on_system_body.begin_type? ? on_system_body.child_nodes : [on_system_body] if child_nodes.all? { |n| n.send_type? || n.block_type? || n.lvasgn_type? } - method_names = child_nodes.map do |node| + method_names = child_nodes.filter_map do |node| next if node.lvasgn_type? next if node.method_name == :patch next if on_system_methods.include? node.method_name node.method_name - end.compact + end next if method_names.empty? || allowed_methods.include?(method_names) end offending_node(on_system_block) diff --git a/Library/Homebrew/search.rb b/Library/Homebrew/search.rb index 14f8d15f01..6c9fa16d11 100644 --- a/Library/Homebrew/search.rb +++ b/Library/Homebrew/search.rb @@ -53,7 +53,7 @@ module Homebrew results = search(Formula.full_names + aliases, string_or_regex).sort results |= Formula.fuzzy_search(string_or_regex).map { |n| Formulary.factory(n).full_name } - results.map do |name| + results.filter_map do |name| formula, canonical_full_name = begin f = Formulary.factory(name) [f, f.full_name] @@ -69,7 +69,7 @@ module Homebrew elsif formula.nil? || formula.valid_platform? name end - end.compact + end end def self.search_casks(string_or_regex) @@ -81,11 +81,11 @@ module Homebrew end end - cask_tokens = Tap.flat_map(&:cask_tokens).map do |c| + cask_tokens = Tap.flat_map(&:cask_tokens).filter_map do |c| next if c.start_with?("homebrew/cask/") && !Homebrew::EnvConfig.no_install_from_api? c.sub(%r{^homebrew/cask.*/}, "") - end.compact + end cask_tokens |= Homebrew::API::Cask.all_casks.keys unless Homebrew::EnvConfig.no_install_from_api? results = search(cask_tokens, string_or_regex) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 8dd3630877..b21df2b0fa 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -228,13 +228,13 @@ class SoftwareSpec def recursive_dependencies deps_f = [] - recursive_dependencies = deps.map do |dep| + recursive_dependencies = deps.filter_map do |dep| deps_f << dep.to_formula dep rescue TapFormulaUnavailableError # Don't complain about missing cross-tap dependencies next - end.compact.uniq + end.uniq deps_f.compact.each do |f| f.recursive_dependencies.each do |dep| recursive_dependencies << dep unless recursive_dependencies.include?(dep) @@ -437,7 +437,7 @@ class Bottle manifests = json["manifests"] raise ArgumentError, "Missing 'manifests' section." if manifests.blank? - manifests_annotations = manifests.map { |m| m["annotations"] }.compact + manifests_annotations = manifests.filter_map { |m| m["annotations"] } raise ArgumentError, "Missing 'annotations' section." if manifests_annotations.blank? bottle_digest = @resource.checksum.hexdigest diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index 817d8a7306..9328198d51 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Homebrew::Diagnostic::Checks do homebrew_path = "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" + ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "") - stub_const("ORIGINAL_PATHS", PATH.new(homebrew_path).map { |path| Pathname.new(path).expand_path }.compact) + stub_const("ORIGINAL_PATHS", PATH.new(homebrew_path).filter_map { |path| Pathname.new(path).expand_path }) expect(checks.check_user_path_1).to be_nil expect(checks.check_user_path_2).to be_nil diff --git a/Library/Homebrew/unlink.rb b/Library/Homebrew/unlink.rb index 043cadffc2..45880161f0 100644 --- a/Library/Homebrew/unlink.rb +++ b/Library/Homebrew/unlink.rb @@ -8,8 +8,7 @@ module Homebrew formula.versioned_formulae .select(&:keg_only?) .select(&:linked?) - .map(&:any_installed_keg) - .compact + .filter_map(&:any_installed_keg) .select(&:directory?) .each do |keg| unlink(keg, verbose: verbose) diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 7d96dd67c5..fcac276a32 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -98,8 +98,7 @@ module UnpackStrategy # For APFS, find the corresponding to eject_paths = disk_info.plist .fetch("APFSPhysicalStores", []) - .map { |store| store["APFSPhysicalStore"] } - .compact + .filter_map { |store| store["APFSPhysicalStore"] } .presence || [path] eject_paths.each do |eject_path| @@ -230,8 +229,7 @@ module UnpackStrategy mounts = if plist.respond_to?(:fetch) plist.fetch("system-entities", []) - .map { |entity| entity["mount-point"] } - .compact + .filter_map { |entity| entity["mount-point"] } .map { |path| Mount.new(path) } else [] diff --git a/Library/Homebrew/unversioned_cask_checker.rb b/Library/Homebrew/unversioned_cask_checker.rb index 3a56ddc33d..b17ea0b33e 100644 --- a/Library/Homebrew/unversioned_cask_checker.rb +++ b/Library/Homebrew/unversioned_cask_checker.rb @@ -222,8 +222,8 @@ module Homebrew top_level_info_plist_paths = top_level_info_plists(Pathname.glob(extract_dir/"**/Contents/Info.plist")) unique_info_plist_versions = - top_level_info_plist_paths.map { |i| BundleVersion.from_info_plist(i)&.nice_version } - .compact.uniq + top_level_info_plist_paths.filter_map { |i| BundleVersion.from_info_plist(i)&.nice_version } + .uniq return unique_info_plist_versions.first if unique_info_plist_versions.count == 1 package_info_path = extract_dir/"PackageInfo" diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index b74fa4ec05..5fc1ea71e8 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -52,7 +52,7 @@ module Homebrew raise CyclicDependencyError, dependency_graph.strongly_connected_components if Homebrew::EnvConfig.developer? end - formula_installers = formulae_to_install.map do |formula| + formula_installers = formulae_to_install.filter_map do |formula| Migrator.migrate_if_needed(formula, force: force, dry_run: dry_run) begin fi = create_formula_installer( @@ -114,7 +114,7 @@ module Homebrew ofail "#{formula}: #{e}" nil end - end.compact + end formula_installers.each do |fi| upgrade_formula(fi, dry_run: dry_run, verbose: verbose) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index de7de99a73..25364b4cac 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -211,7 +211,7 @@ module GitHub reviews = result["repository"]["pullRequest"]["reviews"]["nodes"] valid_associations = %w[MEMBER OWNER] - reviews.map do |r| + reviews.filter_map do |r| next if commit.present? && commit != r["commit"]["oid"] next unless valid_associations.include? r["authorAssociation"] @@ -226,7 +226,7 @@ module GitHub "name" => name, "login" => r["author"]["login"], } - end.compact + end end def self.dispatch_event(user, repo, event, **payload) diff --git a/Library/Homebrew/utils/pypi.rb b/Library/Homebrew/utils/pypi.rb index ffd1fb5ec0..792b966458 100644 --- a/Library/Homebrew/utils/pypi.rb +++ b/Library/Homebrew/utils/pypi.rb @@ -392,11 +392,11 @@ module PyPI def self.pip_report_to_packages(report) return [] if report.blank? - report["install"].map do |package| + report["install"].filter_map do |package| name = normalize_python_package(package["metadata"]["name"]) version = package["metadata"]["version"] Package.new "#{name}==#{version}" - end.compact + end end end diff --git a/Library/Homebrew/utils/spdx.rb b/Library/Homebrew/utils/spdx.rb index 6ff8aef7ce..c7960ed488 100644 --- a/Library/Homebrew/utils/spdx.rb +++ b/Library/Homebrew/utils/spdx.rb @@ -44,14 +44,14 @@ module SPDX licenses.push license_expression when Hash, Array if license_expression.is_a? Hash - license_expression = license_expression.map do |key, value| + license_expression = license_expression.filter_map do |key, value| if key.is_a? String licenses.push key exceptions.push value[:with] next end value - end.compact + end end license_expression.each do |license| diff --git a/Library/Homebrew/utils/topological_hash.rb b/Library/Homebrew/utils/topological_hash.rb index 5879194559..e3db32d217 100644 --- a/Library/Homebrew/utils/topological_hash.rb +++ b/Library/Homebrew/utils/topological_hash.rb @@ -33,8 +33,7 @@ module Utils .reject(&:test?) .map(&:to_formula) cask_deps = cask_or_formula.requirements - .map(&:cask) - .compact + .filter_map(&:cask) .map { |c| Cask::CaskLoader.load(c, config: nil) } end From 921753cf8463b48239783cb0825015ff578526b0 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 22 Feb 2024 23:52:46 +0000 Subject: [PATCH 3/5] Fix RuboCop `Performance/BindCall` offenses --- Library/.rubocop.yml | 2 -- Library/Homebrew/utils.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 67087e5db6..ef81867e2a 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -464,8 +464,6 @@ Style/WordArray: # TODO: Enable these cops once https://github.com/Homebrew/brew/pull/16337#issuecomment-1855668516 is done. Naming/BlockForwarding: Enabled: false -Performance/BindCall: - Enabled: false Style/ArgumentsForwarding: Enabled: false Style/HashSyntax: diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index b8366488b2..9d2fd24455 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -65,7 +65,7 @@ module Homebrew time = Time.now begin - method.bind(self).call(*args, &block) + method.bind_call(self, *args, &block) ensure $times[name] ||= 0 $times[name] += Time.now - time From c11a07db5bf1cf874e1885078a257e8d75babbcd Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 22 Feb 2024 23:57:31 +0000 Subject: [PATCH 4/5] Alphabetize `Style/HashSyntax` RuboCop rule and keep it the same --- Library/.rubocop.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index ef81867e2a..68bbb1b0dc 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -358,6 +358,9 @@ Style/HashAsLastArrayItem: - "/**/Formula/**/*.rb" - "**/Formula/**/*.rb" +Style/HashSyntax: + EnforcedShorthandSyntax: either + Style/InverseMethods: InverseMethods: :blank?: :present? @@ -466,5 +469,3 @@ Naming/BlockForwarding: Enabled: false Style/ArgumentsForwarding: Enabled: false -Style/HashSyntax: - EnforcedShorthandSyntax: either From e654af3e15cf0fd3473813696ff3c37658a9db9e Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 24 Feb 2024 23:53:26 +0000 Subject: [PATCH 5/5] Disable RuboCop `Naming/BlockForwarding` and `Style/ArgumentsForwarding` - These break Sorbet type signatures: ``` RuntimeError: The declaration for is missing parameter(s): & ``` --- Library/.rubocop.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 68bbb1b0dc..eb3ee74832 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -171,6 +171,10 @@ Lint/UnusedMethodArgument: Metrics: Enabled: false +# Disabled because it breaks Sorbet: "The declaration for `with` is missing parameter(s): & (RuntimeError)" +Naming/BlockForwarding: + Enabled: false + # Allow dashes in filenames. Naming/FileName: Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/ @@ -289,6 +293,10 @@ Sorbet/TrueSigil: Style/AndOr: EnforcedStyle: always +# Disabled because it breaks Sorbet: "The declaration for `with` is missing parameter(s): & (RuntimeError)" +Style/ArgumentsForwarding: + Enabled: false + # Avoid leaking resources. Style/AutoResourceCleanup: Enabled: true @@ -463,9 +471,3 @@ Style/UnlessLogicalOperators: # a bit confusing to non-Rubyists but useful for longer arrays Style/WordArray: MinSize: 4 - -# TODO: Enable these cops once https://github.com/Homebrew/brew/pull/16337#issuecomment-1855668516 is done. -Naming/BlockForwarding: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false