Skip to content

Commit 89908c1

Browse files
authored
Merge pull request #5789 from sunny/performance-string-include
RuboCop: Add Performance/StringInclude cop
2 parents d84551b + 56d4e49 commit 89908c1

30 files changed

Lines changed: 56 additions & 42 deletions

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ Naming/HeredocDelimiterNaming:
119119
Performance/StartWith:
120120
Enabled: true
121121

122+
Performance/StringInclude:
123+
Enabled: true
124+
122125
Performance/StringReplacement:
123126
Enabled: true
124127

.rubocop_bundler.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ AllCops:
99
- bundler/**/Rakefile
1010
- bundler/**/Gemfile
1111
- bundler/**/*.rake
12+
- bundler/**/Executable
13+
- bundler/**/Executable.*
1214
Exclude:
1315
- bin/*
1416
- pkg/**/*
@@ -172,6 +174,7 @@ Lint/ScriptPermission:
172174
Enabled: true
173175
Exclude:
174176
- 'bundler/lib/bundler/templates/Executable'
177+
- 'bundler/lib/bundler/templates/Executable.*'
175178

176179
Lint/ShadowedArgument:
177180
Enabled: true
@@ -480,6 +483,9 @@ Performance/Size:
480483
Performance/StartWith:
481484
Enabled: true
482485

486+
Performance/StringInclude:
487+
Enabled: true
488+
483489
Performance/StringReplacement:
484490
Enabled: true
485491

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ file "pkg/rubygems-#{v}.tgz" => "pkg/rubygems-#{v}" do
253253
sh "7z a -tgzip rubygems-#{v}.tgz rubygems-#{v}.tar"
254254
else
255255
tar_version = `tar --version`
256-
if tar_version =~ /bsdtar/
256+
if tar_version.include?("bsdtar")
257257
# bsdtar, as used by at least FreeBSD and macOS, uses `--uname` and `--gname`.
258258
sh "tar -czf rubygems-#{v}.tgz --uname=rubygems:0 --gname=rubygems:0 rubygems-#{v}"
259259
else # If a third variant is added, change this line to: elsif tar_version =~ /GNU tar/

bin/update_rubygems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ unless ARGV.grep(/--version=([\d\.]*)/).empty?
2020
exec Gem.ruby, "-S", $PROGRAM_NAME, "_#{$1}_"
2121
end
2222

23-
update_dir = $LOAD_PATH.find {|dir| dir =~ /rubygems-update/ }
23+
update_dir = $LOAD_PATH.find {|dir| dir.include?("rubygems-update") }
2424

2525
if update_dir.nil?
2626
puts "Error: Cannot find RubyGems update path!"

bundler/doc/development/PULL_REQUESTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Before you submit a pull request, please remember to do the following:
1010

1111
Make sure the code formatting and styling adheres to the guidelines. We use RuboCop for this. Lack of formatting adherence will result in automatic GitHub Actions build failures.
1212

13+
$ cd bundler
1314
$ bin/rubocop -a
1415

1516
## Tests

bundler/lib/bundler/cli/viz.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def run
2323
Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
2424
Bundler.ui.warn "`gem install ruby-graphviz`"
2525
rescue StandardError => e
26-
raise unless e.message =~ /GraphViz not installed or dot not in PATH/
26+
raise unless e.message.to_s.include?("GraphViz not installed or dot not in PATH")
2727
Bundler.ui.error e.message
2828
Bundler.ui.warn "Please install GraphViz. On a Mac with Homebrew, you can run `brew install graphviz`."
2929
end

bundler/lib/bundler/constants.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Bundler
44
WINDOWS = RbConfig::CONFIG["host_os"] =~ /(msdos|mswin|djgpp|mingw)/
5-
FREEBSD = RbConfig::CONFIG["host_os"] =~ /bsd/
5+
FREEBSD = RbConfig::CONFIG["host_os"].to_s.include?("bsd")
66
NULL = WINDOWS ? "NUL" : "/dev/null"
77
end

bundler/lib/bundler/fetcher/downloader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def request(uri, headers)
6868
raise CertificateFailureError.new(uri)
6969
rescue *HTTP_ERRORS => e
7070
Bundler.ui.trace e
71-
if e.is_a?(SocketError) || e.message =~ /host down:/
71+
if e.is_a?(SocketError) || e.message.to_s.include?("host down:")
7272
raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
7373
"connection and try again."
7474
else

bundler/lib/bundler/templates/Executable

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("<%= relative_gemfile_path %>", __dir
1313
bundle_binstub = File.expand_path("bundle", __dir__)
1414

1515
if File.file?(bundle_binstub)
16-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
16+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
1717
load(bundle_binstub)
1818
else
1919
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.

bundler/lib/bundler/templates/Executable.bundler

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ m = Module.new do
6262

6363
def bundler_requirement
6464
@bundler_requirement ||=
65-
env_var_version || cli_arg_version ||
66-
bundler_requirement_for(lockfile_version)
65+
env_var_version ||
66+
cli_arg_version ||
67+
bundler_requirement_for(lockfile_version)
6768
end
6869

6970
def bundler_requirement_for(version)

0 commit comments

Comments
 (0)