From 17c390df99e6f0b6d78255ef00103e6ec29f3f9b Mon Sep 17 00:00:00 2001 From: Peter Leitzen <pleitzen@gitlab.com> Date: Mon, 30 Jan 2023 21:45:44 +0100 Subject: [PATCH] Auto-correct remaining offenses for Performance/StringInclude String#include? is much faster than Regexp#match (etc.) --- .rubocop_todo/performance/string_include.yml | 13 ------------- app/models/snippet_repository.rb | 2 +- config/initializers/macos.rb | 2 +- config/spring.rb | 2 +- ee/app/models/ee/container_registry/event.rb | 2 +- ee/lib/gitlab/auth/smartcard/certificate.rb | 4 ++-- ee/spec/models/container_registry/event_spec.rb | 8 ++++++++ lib/kramdown/parser/atlassian_document_format.rb | 2 +- lib/prometheus/pid_provider.rb | 2 +- spec/features/projects/jobs_spec.rb | 2 +- spec/spec_helper.rb | 4 ++-- 11 files changed, 19 insertions(+), 24 deletions(-) delete mode 100644 .rubocop_todo/performance/string_include.yml diff --git a/.rubocop_todo/performance/string_include.yml b/.rubocop_todo/performance/string_include.yml deleted file mode 100644 index 2a2d0559397a6..0000000000000 --- a/.rubocop_todo/performance/string_include.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# Cop supports --autocorrect. -Performance/StringInclude: - Exclude: - - 'app/models/snippet_repository.rb' - - 'config/initializers/macos.rb' - - 'config/spring.rb' - - 'ee/app/models/ee/container_registry/event.rb' - - 'ee/lib/gitlab/auth/smartcard/certificate.rb' - - 'lib/kramdown/parser/atlassian_document_format.rb' - - 'lib/prometheus/pid_provider.rb' - - 'spec/features/projects/jobs_spec.rb' - - 'spec/spec_helper.rb' diff --git a/app/models/snippet_repository.rb b/app/models/snippet_repository.rb index a959ad4d548dd..9139dc22a94b8 100644 --- a/app/models/snippet_repository.rb +++ b/app/models/snippet_repository.rb @@ -121,7 +121,7 @@ def invalid_path_error?(err) def invalid_signature_error?(err) err.is_a?(ArgumentError) && - err.message.downcase.match?(/failed to parse signature/) + err.message.downcase.include?('failed to parse signature') end def only_rename_action?(action) diff --git a/config/initializers/macos.rb b/config/initializers/macos.rb index 1edd6c0a730c7..3b669a73f4950 100644 --- a/config/initializers/macos.rb +++ b/config/initializers/macos.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if /darwin/ =~ RUBY_PLATFORM +if RUBY_PLATFORM.include?('darwin') Gitlab::Cluster::LifecycleEvents.on_before_fork do require 'fiddle' diff --git a/config/spring.rb b/config/spring.rb index 3f00e6ab23fb2..f06a707111ccf 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -10,7 +10,7 @@ Spring.after_fork do if ENV['DEBUGGER_STORED_RUBYLIB'] ENV['DEBUGGER_STORED_RUBYLIB'].split(File::PATH_SEPARATOR).each do |path| - next unless path =~ /ruby-debug-ide/ + next unless path.include?('ruby-debug-ide') load path + '/ruby-debug-ide/multiprocess/starter.rb' end diff --git a/ee/app/models/ee/container_registry/event.rb b/ee/app/models/ee/container_registry/event.rb index ad09df1cce8c2..91cdbd2c6b37d 100644 --- a/ee/app/models/ee/container_registry/event.rb +++ b/ee/app/models/ee/container_registry/event.rb @@ -22,7 +22,7 @@ def handle_after_update! end def media_type_manifest? - event.dig('target', 'mediaType') =~ /manifest/ + event.dig('target', 'mediaType')&.include?('manifest') end def find_container_repository! diff --git a/ee/lib/gitlab/auth/smartcard/certificate.rb b/ee/lib/gitlab/auth/smartcard/certificate.rb index 59377c2d22b08..0a9ea341010dc 100644 --- a/ee/lib/gitlab/auth/smartcard/certificate.rb +++ b/ee/lib/gitlab/auth/smartcard/certificate.rb @@ -51,7 +51,7 @@ def subject end def common_name - subject.split('/').find { |part| part =~ /CN=/ }&.remove('CN=')&.strip + subject.split('/').find { |part| part.include?('CN=') }&.remove('CN=')&.strip end def email @@ -59,7 +59,7 @@ def email if san_enabled? san_extension.email_identity else - subject.split('/').find { |part| part =~ /emailAddress=/ }&.remove('emailAddress=')&.strip + subject.split('/').find { |part| part.include?('emailAddress=') }&.remove('emailAddress=')&.strip end end end diff --git a/ee/spec/models/container_registry/event_spec.rb b/ee/spec/models/container_registry/event_spec.rb index 6d741e44ebd35..506a844a4c653 100644 --- a/ee/spec/models/container_registry/event_spec.rb +++ b/ee/spec/models/container_registry/event_spec.rb @@ -76,6 +76,14 @@ with_them do it_behaves_like params[:example_name] end + + context 'without media type' do + let(:action) { 'push' } + let(:repository_path) { 'group/test/container_repository' } + let(:target) { super().without('mediaType') } + + it_behaves_like 'not creating a geo event' + end end end end diff --git a/lib/kramdown/parser/atlassian_document_format.rb b/lib/kramdown/parser/atlassian_document_format.rb index 4ceb879a04c31..d27697a59a6f2 100644 --- a/lib/kramdown/parser/atlassian_document_format.rb +++ b/lib/kramdown/parser/atlassian_document_format.rb @@ -219,7 +219,7 @@ def process_mention(element, ast_node) # opportunity to replace it later. Mention name can have # spaces, so double quote it mention_text = ast_node.dig('attrs', 'text')&.gsub('@', '') - mention_text = %Q("#{mention_text}") if mention_text.match?(/ /) + mention_text = %Q("#{mention_text}") if mention_text&.include?(' ') mention_text = %Q(@adf-mention:#{mention_text}) add_text(mention_text, element, :text) diff --git a/lib/prometheus/pid_provider.rb b/lib/prometheus/pid_provider.rb index 05a2d3bd0c9b6..4d38e9513fb07 100644 --- a/lib/prometheus/pid_provider.rb +++ b/lib/prometheus/pid_provider.rb @@ -27,7 +27,7 @@ def sidekiq_worker_id def puma_worker_id if matches = process_name.match(/puma.*cluster worker ([0-9]+):/) "puma_#{matches[1]}" - elsif process_name =~ /puma/ + elsif process_name.include?('puma') "puma_master" else unknown_process_id diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index 4734a607ef16e..40562d22a411b 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -302,7 +302,7 @@ click_link 'Download' end - artifact_request = requests.find { |req| req.url.match(%r{artifacts/download}) } + artifact_request = requests.find { |req| req.url.include?('artifacts/download') } expect(artifact_request.response_headers['Content-Disposition']).to eq(%Q{attachment; filename="#{job.artifacts_file.filename}"; filename*=UTF-8''#{job.artifacts_file.filename}}) expect(artifact_request.response_headers['Content-Transfer-Encoding']).to eq("binary") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7f2510c5ab90f..2d3afb489df08 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,7 +44,7 @@ ENV['RSPEC_PROFILING'] branch_can_be_profiled = (ENV['CI_COMMIT_REF_NAME'] == 'master' || - ENV['CI_COMMIT_REF_NAME'] =~ /rspec-profile/) + ENV['CI_COMMIT_REF_NAME']&.include?('rspec-profile')) if rspec_profiling_is_configured && (!ENV.key?('CI') || branch_can_be_profiled) require 'rspec_profiling/rspec' @@ -105,7 +105,7 @@ location = metadata[:location] metadata[:level] = quality_level.level_for(location) - metadata[:api] = true if location =~ %r{/spec/requests/api/} + metadata[:api] = true if location.include?('/spec/requests/api/') # Do not overwrite migration if it's already set unless metadata.key?(:migration) -- GitLab