From a881b33818b101ad097cd0158afda11b6c24f1fc Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 4 Apr 2023 12:03:13 +0900 Subject: [rubygems/rubygems] util/rubocop -A --only Performance/RegexpMatch https://github.com/rubygems/rubygems/commit/52ae4452c2 --- lib/rubygems/command.rb | 2 +- lib/rubygems/commands/unpack_command.rb | 4 ++-- lib/rubygems/config_file.rb | 4 ++-- lib/rubygems/dependency_installer.rb | 2 +- lib/rubygems/doctor.rb | 2 +- lib/rubygems/ext/rake_builder.rb | 2 +- lib/rubygems/installer.rb | 8 ++++---- lib/rubygems/local_remote_options.rb | 2 +- lib/rubygems/package/tar_header.rb | 4 ++-- lib/rubygems/path_support.rb | 2 +- lib/rubygems/platform.rb | 2 +- lib/rubygems/remote_fetcher.rb | 2 +- lib/rubygems/resolver.rb | 2 +- lib/rubygems/specification_policy.rb | 12 ++++++------ lib/rubygems/uri_formatter.rb | 2 +- lib/rubygems/version.rb | 2 +- 16 files changed, 27 insertions(+), 27 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index d0620288c4..53bb609ae0 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -457,7 +457,7 @@ class Gem::Command until extra.empty? do ex = [] ex << extra.shift - ex << extra.shift if extra.first.to_s =~ /^[^-]/ + ex << extra.shift if /^[^-]/.match?(extra.first.to_s) result << ex if handles?(ex) end diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index 492cf7fe43..73eefe153c 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -151,7 +151,7 @@ command help for an example. # source directories? def get_path(dependency) - return dependency.name if dependency.name =~ /\.gem$/i + return dependency.name if /\.gem$/i.match?(dependency.name) specs = dependency.matching_specs @@ -160,7 +160,7 @@ command help for an example. return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless selected - return unless dependency.name =~ /^#{selected.name}$/i + return unless /^#{selected.name}$/i.match?(dependency.name) # We expect to find (basename).gem in the 'cache' directory. Furthermore, # the name match must be exact (ignoring case). diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 9017415308..0a5f6ffad2 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -483,7 +483,7 @@ if you believe they were disclosed to a third party. @hash.each do |key, value| key = key.to_s - next if key =~ re + next if key&.match?(re) yaml_hash[key.to_s] = value end @@ -534,7 +534,7 @@ if you believe they were disclosed to a third party. need_config_file_name = false elsif arg =~ /^--config-file=(.*)/ @config_file_name = $1 - elsif arg =~ /^--config-file$/ + elsif /^--config-file$/.match?(arg) need_config_file_name = true end end diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 3cf41d2476..56a9309a7e 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -291,7 +291,7 @@ class Gem::DependencyInstaller src = Gem::Source::SpecificFile.new dep_or_name installer_set.add_local dep_or_name, src.spec, src version = src.spec.version if version == Gem::Requirement.default - elsif dep_or_name =~ /\.gem$/ + elsif dep_or_name =~ /\.gem$/ # rubocop:disable Performance/RegexpMatch Dir[dep_or_name].each do |name| src = Gem::Source::SpecificFile.new name installer_set.add_local dep_or_name, src.spec, src diff --git a/lib/rubygems/doctor.rb b/lib/rubygems/doctor.rb index 6fdf5da7d4..b0fb01c048 100644 --- a/lib/rubygems/doctor.rb +++ b/lib/rubygems/doctor.rb @@ -111,7 +111,7 @@ class Gem::Doctor basename = File.basename(child, extension) next if installed_specs.include? basename - next if /^rubygems-\d/ =~ basename + next if /^rubygems-\d/.match?(basename) next if sub_directory == "specifications" && basename == "default" next if sub_directory == "plugins" && Gem.plugin_suffix_regexp =~ (basename) diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index 8fa14f2128..2b9a23a23f 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -8,7 +8,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=Dir.pwd) - if File.basename(extension) =~ /mkrf_conf/i + if /mkrf_conf/i.match?(File.basename(extension)) run([Gem.ruby, File.basename(extension), *args], results, class_name, extension_dir) end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index fdb2944272..b73f3a493b 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -230,7 +230,7 @@ class Gem::Installer end end - next unless line =~ shebang + next unless line&.match?(shebang) io.gets # blankline @@ -714,7 +714,7 @@ class Gem::Installer end def verify_spec - unless spec.name =~ Gem::Specification::VALID_NAME_PATTERN + unless Gem::Specification::VALID_NAME_PATTERN.match?(spec.name) raise Gem::InstallError, "#{spec} has an invalid name" end @@ -726,11 +726,11 @@ class Gem::Installer raise Gem::InstallError, "#{spec} has an invalid extensions" end - if spec.platform.to_s =~ /\R/ + if /\R/.match?(spec.platform.to_s) raise Gem::InstallError, "#{spec.platform} is an invalid platform" end - unless spec.specification_version.to_s =~ /\A\d+\z/ + unless /\A\d+\z/.match?(spec.specification_version.to_s) raise Gem::InstallError, "#{spec} has an invalid specification_version" end diff --git a/lib/rubygems/local_remote_options.rb b/lib/rubygems/local_remote_options.rb index 23cd6d0076..5934ff7682 100644 --- a/lib/rubygems/local_remote_options.rb +++ b/lib/rubygems/local_remote_options.rb @@ -103,7 +103,7 @@ module Gem::LocalRemoteOptions add_option(:"Local/Remote", "-s", "--source URL", URI::HTTP, "Append URL to list of remote gem sources") do |source, options| - source << "/" if source !~ /\/\z/ + source << "/" if !/\/\z/.match?(source) if options.delete :sources_cleared Gem.sources = [source] diff --git a/lib/rubygems/package/tar_header.rb b/lib/rubygems/package/tar_header.rb index 0bec8f4845..11d66210a4 100644 --- a/lib/rubygems/package/tar_header.rb +++ b/lib/rubygems/package/tar_header.rb @@ -127,7 +127,7 @@ class Gem::Package::TarHeader end def self.strict_oct(str) - return str.strip.oct if str.strip =~ /\A[0-7]*\z/ + return str.strip.oct if /\A[0-7]*\z/.match?(str.strip) raise ArgumentError, "#{str.inspect} is not an octal string" end @@ -137,7 +137,7 @@ class Gem::Package::TarHeader # \ff flags a negative 256-based number # In case we have a match, parse it as a signed binary value # in big-endian order, except that the high-order bit is ignored. - return str.unpack("N2").last if str =~ /\A[\x80\xff]/n + return str.unpack("N2").last if /\A[\x80\xff]/n.match?(str) strict_oct(str) end diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index d9df543ad9..b596b4f6b8 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -53,7 +53,7 @@ class Gem::PathSupport gem_path = gpaths.split(Gem.path_separator) # Handle the path_separator being set to a regexp, which will cause # end_with? to error - if gpaths =~ /#{Gem.path_separator}\z/ + if /#{Gem.path_separator}\z/.match?(gpaths) gem_path += default_path end diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 89ae3ad412..cccfa06ae9 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -14,7 +14,7 @@ class Gem::Platform def self.local arch = RbConfig::CONFIG["arch"] - arch = "#{arch}_60" if arch =~ /mswin(?:32|64)$/ + arch = "#{arch}_60" if /mswin(?:32|64)$/.match?(arch) @local ||= new(arch) end diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 5fd7d9a85a..f9f8c45817 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -136,7 +136,7 @@ class Gem::RemoteFetcher scheme = source_uri.scheme # URI.parse gets confused by MS Windows paths with forward slashes. - scheme = nil if scheme =~ /^[a-z]$/i + scheme = nil if /^[a-z]$/i.match?(scheme) # REFACTOR: split this up and dispatch on scheme (eg download_http) # REFACTOR: be sure to clean up fake fetcher when you do this... cleaner diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index 3648296766..8b9d41b40f 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -247,7 +247,7 @@ class Gem::Resolver sources.each do |source| groups[source]. - sort_by {|spec| [spec.version, spec.platform =~ Gem::Platform.local ? 1 : 0] }. + sort_by {|spec| [spec.version, spec.platform =~ Gem::Platform.local ? 1 : 0] }. # rubocop:disable Performance/RegexpMatch map {|spec| ActivationRequest.new spec, dependency }. each {|activation_request| activation_requests << activation_request } end diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index a5e7499531..19537a873d 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -144,7 +144,7 @@ class Gem::SpecificationPolicy end next unless METADATA_LINK_KEYS.include? key - if value !~ VALID_URI_PATTERN + if !VALID_URI_PATTERN.match?(value) error "#{entry} has invalid link: #{value.inspect}" end end @@ -279,11 +279,11 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use: if !name.is_a?(String) error "invalid value for attribute name: \"#{name.inspect}\" must be a string" - elsif name !~ /[a-zA-Z]/ + elsif !/[a-zA-Z]/.match?(name) error "invalid value for attribute name: #{name.dump} must include at least one letter" - elsif name !~ VALID_NAME_PATTERN + elsif !VALID_NAME_PATTERN.match?(name) error "invalid value for attribute name: #{name.dump} can only include letters, numbers, dashes, and underscores" - elsif name =~ SPECIAL_CHARACTERS + elsif SPECIAL_CHARACTERS.match?(name) error "invalid value for attribute name: #{name.dump} can not begin with a period, dash, or underscore" end end @@ -397,11 +397,11 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li error "#{LAZY} is not an email" end - if @specification.description =~ LAZY_PATTERN + if LAZY_PATTERN.match?(@specification.description) error "#{LAZY} is not a description" end - if @specification.summary =~ LAZY_PATTERN + if LAZY_PATTERN.match?(@specification.summary) error "#{LAZY} is not a summary" end diff --git a/lib/rubygems/uri_formatter.rb b/lib/rubygems/uri_formatter.rb index 7429570b71..517ce33637 100644 --- a/lib/rubygems/uri_formatter.rb +++ b/lib/rubygems/uri_formatter.rb @@ -34,7 +34,7 @@ class Gem::UriFormatter # Normalize the URI by adding "http://" if it is missing. def normalize - @uri =~ /^(https?|ftp|file):/i ? @uri : "http://#{@uri}" + /^(https?|ftp|file):/i.match?(@uri) ? @uri : "http://#{@uri}" end ## diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 8fc4e1b327..3d8e11b515 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -405,7 +405,7 @@ class Gem::Version # since this version object is cached in @@all, its @segments should be frozen @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| - /^\d+$/ =~ s ? s.to_i : s + /^\d+$/.match?(s) ? s.to_i : s end.freeze end -- cgit v1.2.3