diff options
author | David RodrÃguez <[email protected]> | 2024-11-18 20:53:48 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-11-26 15:11:05 +0900 |
commit | 963f98a94f978552c9ceb413dab085d2cdfc1236 (patch) | |
tree | 19043e52ff1637468418faef6aaa81eba3ddf017 | |
parent | 4addaaf4df9a7b48c3490b806c195fcb7be999b5 (diff) |
[rubygems/rubygems] Enable `Performance/MapCompact` cop
https://github.com/rubygems/rubygems/commit/0c3a65871a
-rw-r--r-- | lib/bundler/cli/doctor.rb | 4 | ||||
-rw-r--r-- | lib/bundler/cli/info.rb | 4 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 2 | ||||
-rw-r--r-- | lib/bundler/dependency.rb | 2 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 2 | ||||
-rw-r--r-- | lib/bundler/gem_helpers.rb | 2 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 4 | ||||
-rw-r--r-- | lib/bundler/resolver/base.rb | 4 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 4 | ||||
-rw-r--r-- | lib/bundler/source/path.rb | 4 | ||||
-rw-r--r-- | lib/rubygems/commands/contents_command.rb | 4 | ||||
-rw-r--r-- | lib/rubygems/ext/cargo_builder.rb | 3 | ||||
-rw-r--r-- | lib/rubygems/resolver.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/source/git.rb | 4 | ||||
-rw-r--r-- | spec/bundler/support/artifice/helpers/endpoint.rb | 4 | ||||
-rw-r--r-- | spec/bundler/support/matchers.rb | 8 |
16 files changed, 28 insertions, 29 deletions
diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index 76b37d81cd..ce016e3ad2 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -32,11 +32,11 @@ module Bundler def dylibs_ldd(path) output = `/usr/bin/ldd #{path.shellescape}`.chomp - output.split("\n").map do |l| + output.split("\n").filter_map do |l| match = l.match(LDD_REGEX) next if match.nil? match.captures[0] - end.compact + end end def dylibs(path) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 8f34956aca..d7a8530fba 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -73,11 +73,11 @@ module Bundler end def gem_dependencies - @gem_dependencies ||= Bundler.definition.specs.map do |spec| + @gem_dependencies ||= Bundler.definition.specs.filter_map do |spec| dependency = spec.dependencies.find {|dep| dep.name == gem_name } next unless dependency "#{spec.name} (#{spec.version}) depends on #{gem_name} (#{dependency.requirements_list.join(", ")})" - end.compact.sort + end.sort end end end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 871e860886..45171d348f 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -341,7 +341,7 @@ module Bundler end def spec_git_paths - sources.git_sources.map {|s| File.realpath(s.path) if File.exist?(s.path) }.compact + sources.git_sources.filter_map {|s| File.realpath(s.path) if File.exist?(s.path) } end def groups diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 2a4f72fe55..32d5b47f94 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -62,7 +62,7 @@ module Bundler end def expanded_platforms - @expanded_platforms ||= @platforms.map {|pl| PLATFORM_MAP[pl] }.compact.flatten.uniq + @expanded_platforms ||= @platforms.filter_map {|pl| PLATFORM_MAP[pl] }.flatten.uniq end def should_include? diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index a7b7df84a6..05c60f2f1a 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -66,7 +66,7 @@ module Bundler development_group = opts[:development_group] || :development expanded_path = gemfile_root.join(path) - gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact + gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).filter_map {|g| Bundler.load_gemspec(g) } gemspecs.reject! {|s| s.name != name } if name specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] } diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index 5314b7abc8..f123e7827e 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -63,7 +63,7 @@ module Bundler module_function :select_best_platform_match def select_best_local_platform_match(specs, force_ruby: false, most_specific_locked_platform: nil) - select_best_platform_match(specs, local_platform, force_ruby: force_ruby).map {|spec| spec.materialize_for_installation(most_specific_locked_platform) }.compact + select_best_platform_match(specs, local_platform, force_ruby: force_ruby).filter_map {|spec| spec.materialize_for_installation(most_specific_locked_platform) } end module_function :select_best_local_platform_match diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index c37eabdccc..89bc6d5324 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -417,7 +417,7 @@ module Bundler end def prepare_dependencies(requirements, packages) - to_dependency_hash(requirements, packages).map do |dep_package, dep_constraint| + to_dependency_hash(requirements, packages).filter_map do |dep_package, dep_constraint| name = dep_package.name next [dep_package, dep_constraint] if name == "bundler" @@ -443,7 +443,7 @@ module Bundler next unless dep_package.current_platform? raise_not_found!(dep_package) - end.compact.to_h + end.to_h end def select_sorted_versions(package, range) diff --git a/lib/bundler/resolver/base.rb b/lib/bundler/resolver/base.rb index 4c2aed32de..078bde0fd1 100644 --- a/lib/bundler/resolver/base.rb +++ b/lib/bundler/resolver/base.rb @@ -16,7 +16,7 @@ module Bundler hash[name] = Package.new(name, platforms, **options) end - @requirements = dependencies.map do |dep| + @requirements = dependencies.filter_map do |dep| dep_platforms = dep.gem_platforms(platforms) # Dependencies scoped to external platforms are ignored @@ -27,7 +27,7 @@ module Bundler @packages[name] = Package.new(name, dep_platforms, **options.merge(dependency: dep)) dep - end.compact + end end def specs_compatible_with(result) diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 9792a81962..dceb1b1c5a 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -263,10 +263,10 @@ module Bundler def setup_manpath # Add man/ subdirectories from activated bundles to MANPATH for man(1) - manuals = $LOAD_PATH.map do |path| + manuals = $LOAD_PATH.filter_map do |path| man_subdir = path.sub(/lib$/, "man") man_subdir unless Dir[man_subdir + "/man?/"].empty? - end.compact + end return if manuals.empty? Bundler::SharedHelpers.set_env "MANPATH", manuals.concat( diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index d4c530e922..a24cd8159e 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -214,7 +214,7 @@ module Bundler # Some gem authors put absolute paths in their gemspec # and we have to save them from themselves - spec.files = spec.files.map do |path| + spec.files = spec.files.filter_map do |path| next path unless /\A#{Pathname::SEPARATOR_PAT}/o.match?(path) next if File.directory?(path) begin @@ -222,7 +222,7 @@ module Bundler rescue ArgumentError path end - end.compact + end installer = Path::Installer.new( spec, diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index 390ae2a923..d4f9871868 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -102,7 +102,7 @@ prefix or only the files that are requireable. end def files_in_default_gem(spec) - spec.files.map do |file| + spec.files.filter_map do |file| if file.start_with?("#{spec.bindir}/") [RbConfig::CONFIG["bindir"], file.delete_prefix("#{spec.bindir}/")] else @@ -119,7 +119,7 @@ prefix or only the files that are requireable. [resolve.delete_suffix(requirable_part), requirable_part] end - end.compact + end end def gem_contents(name) diff --git a/lib/rubygems/ext/cargo_builder.rb b/lib/rubygems/ext/cargo_builder.rb index 81b28c3c77..453f8d5bcb 100644 --- a/lib/rubygems/ext/cargo_builder.rb +++ b/lib/rubygems/ext/cargo_builder.rb @@ -252,8 +252,7 @@ EOF def rustc_dynamic_linker_flags(dest_dir, crate_name) split_flags("DLDFLAGS"). - map {|arg| maybe_resolve_ldflag_variable(arg, dest_dir, crate_name) }. - compact. + filter_map {|arg| maybe_resolve_ldflag_variable(arg, dest_dir, crate_name) }. flat_map {|arg| ldflag_to_link_modifier(arg) } end diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 6b74c2527a..35d83abd2d 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -183,7 +183,7 @@ class Gem::Resolver # Proceed with resolution! Returns an array of ActivationRequest objects. def resolve - Gem::Molinillo::Resolver.new(self, self).resolve(@needed.map {|d| DependencyRequest.new d, nil }).tsort.map(&:payload).compact + Gem::Molinillo::Resolver.new(self, self).resolve(@needed.map {|d| DependencyRequest.new d, nil }).tsort.filter_map(&:payload) rescue Gem::Molinillo::VersionConflict => e conflict = e.conflicts.values.first raise Gem::DependencyResolutionError, Conflict.new(conflict.requirement_trees.first.first, conflict.existing, conflict.requirement) diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb index 34f6851bc4..f229e1a7be 100644 --- a/lib/rubygems/source/git.rb +++ b/lib/rubygems/source/git.rb @@ -201,7 +201,7 @@ class Gem::Source::Git < Gem::Source return [] unless install_dir Dir.chdir install_dir do - Dir["{,*,*/*}.gemspec"].map do |spec_file| + Dir["{,*,*/*}.gemspec"].filter_map do |spec_file| directory = File.dirname spec_file file = File.basename spec_file @@ -218,7 +218,7 @@ class Gem::Source::Git < Gem::Source end spec end - end.compact + end end end diff --git a/spec/bundler/support/artifice/helpers/endpoint.rb b/spec/bundler/support/artifice/helpers/endpoint.rb index 5d342c07ef..0546c267eb 100644 --- a/spec/bundler/support/artifice/helpers/endpoint.rb +++ b/spec/bundler/support/artifice/helpers/endpoint.rb @@ -66,7 +66,7 @@ class Endpoint < Sinatra::Base Marshal.load(File.binread(gem_repo.join(filename))) end.inject(:+) - all_specs.map do |name, version, platform| + all_specs.filter_map do |name, version, platform| spec = load_spec(name, version, platform, gem_repo) next unless gem_names.include?(spec.name) { @@ -77,7 +77,7 @@ class Endpoint < Sinatra::Base [dep.name, dep.requirement.requirements.map {|a| a.join(" ") }.join(", ")] end, } - end.compact + end end def load_spec(name, version, platform, gem_repo) diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index ed11e3ba52..9f311fc0d7 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -116,7 +116,7 @@ module Spec source = opts.delete(:source) groups = Array(opts.delete(:groups)).map(&:inspect).join(", ") opts[:raise_on_error] = false - @errors = names.map do |full_name| + @errors = names.filter_map do |full_name| name, version, platform = full_name.split(/\s+/) platform ||= "ruby" require_path = name.tr("-", "/") @@ -159,7 +159,7 @@ module Spec next "Expected #{name} (#{version}) to be installed from `#{source}`, was actually from `#{actual_source}`" end next "Command to check for inclusion of gem #{full_name} failed" - end.compact + end @errors.empty? end @@ -168,7 +168,7 @@ module Spec opts = names.last.is_a?(Hash) ? names.pop : {} groups = Array(opts.delete(:groups)).map(&:inspect).join(", ") opts[:raise_on_error] = false - @errors = names.map do |name| + @errors = names.filter_map do |name| name, version = name.split(/\s+/, 2) ruby <<-R, opts begin @@ -194,7 +194,7 @@ module Spec next "command to check version of #{name} installed failed" unless exitstatus == 64 next "expected #{name} to not be installed, but it was" if version.nil? next "expected #{name} (#{version}) not to be installed, but it was" - end.compact + end @errors.empty? end |