[前][次][番号順一覧][スレッド一覧]

ruby-changes:61549

From: Olle <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:31 +0900 (JST)
Subject: [ruby-changes:61549] 5eacf4e72c (master): Enable rubocop-performance StartWith cop

https://git.ruby-lang.org/ruby.git/commit/?id=5eacf4e72c

From 5eacf4e72cffadde3c4c2b6dada6cd5343310ae3 Mon Sep 17 00:00:00 2001
From: Olle Jonsson <olle.jonsson@a...>
Date: Sun, 19 Apr 2020 22:39:42 +0200
Subject: Enable rubocop-performance StartWith cop

  - this would keep the could-be-a-string-method matches few

diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index 1c9ce03..f08749b 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -456,9 +456,7 @@ class Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/command.rb#L456
     until extra.empty? do
       ex = []
       ex << extra.shift
-      if (!extra.first.to_s.empty? && !extra.first.to_s.start_with?("-"))
-        ex << extra.shift
-      end
+      ex << extra.shift if extra.first.to_s =~ /^[^-]/ # rubocop:disable Performance/StartWith
       result << ex if handles?(ex)
     end
 
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index cf67685..92e6126 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -584,9 +584,9 @@ class Gem::Installer https://github.com/ruby/ruby/blob/trunk/lib/rubygems/installer.rb#L584
   def shebang(bin_file_name)
     ruby_name = RbConfig::CONFIG['ruby_install_name'] if @env_shebang
     path = File.join gem_dir, spec.bindir, bin_file_name
-    first_line = File.open(path, "rb") {|file| file.gets}
+    first_line = File.open(path, "rb") {|file| file.gets} || ""
 
-    if /\A#!/ =~ first_line
+    if first_line.start_with?("#!")
       # Preserve extra words on shebang line, like "-w".  Thanks RPA.
       shebang = first_line.sub(/\A\#!.*?ruby\S*((\s+\S+)+)/, "#!#{Gem.ruby}")
       opts = $1
diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index 1692eb7..868a9de 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -150,7 +150,7 @@ class Gem::Platform https://github.com/ruby/ruby/blob/trunk/lib/rubygems/platform.rb#L150
 
     # cpu
     ([nil,'universal'].include?(@cpu) or [nil, 'universal'].include?(other.cpu) or @cpu == other.cpu or
-    (@cpu == 'arm' and other.cpu =~ /\Aarm/)) and
+    (@cpu == 'arm' and other.cpu.start_with?("arm"))) and
 
     # os
     @os == other.os and
diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb
index 8fb1b1d..cc1d109 100644
--- a/lib/rubygems/security/signer.rb
+++ b/lib/rubygems/security/signer.rb
@@ -109,7 +109,7 @@ class Gem::Security::Signer https://github.com/ruby/ruby/blob/trunk/lib/rubygems/security/signer.rb#L109
     subject_alt_name = cert.extensions.find { |e| 'subjectAltName' == e.oid }
 
     if subject_alt_name
-      /\Aemail:/ =~ subject_alt_name.value
+      /\Aemail:/ =~ subject_alt_name.value # rubocop:disable Performance/StartWith
 
       $' || subject_alt_name.value
     else
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 1d69807..362cb37 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1151,7 +1151,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1151
 
   def self.normalize_yaml_input(input)
     result = input.respond_to?(:read) ? input.read : input
-    result = "--- " + result unless result =~ /\A--- /
+    result = "--- " + result unless result.start_with?("--- ")
     result = result.dup
     result.gsub!(/ !!null \n/, " \n")
     # date: 2011-04-26 00:00:00.000000000Z
@@ -2104,7 +2104,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2104
     end
 
     if @specification_version > CURRENT_SPECIFICATION_VERSION and
-        sym.to_s.end_with?("=")
+      sym.to_s.end_with?("=")
       warn "ignoring #{sym} loading #{full_name}" if $DEBUG
     else
       super
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]