diff --git a/.rubocop_todo/performance/regexp_match.yml b/.rubocop_todo/performance/regexp_match.yml index c1a8036f8d14c3df55b8ed27bf5ac3d35105485f..888552f876c7c4b15178e58bbe385a2109eccdb2 100644 --- a/.rubocop_todo/performance/regexp_match.yml +++ b/.rubocop_todo/performance/regexp_match.yml @@ -72,8 +72,6 @@ Performance/RegexpMatch: - 'qa/qa/service/cluster_provider/k3d.rb' - 'qa/qa/specs/spec_helper.rb' - 'qa/qa/tools/ci/ff_changes.rb' - - 'rubocop/cop/project_path_helper.rb' - - 'rubocop/cop/qa/selector_usage.rb' - 'scripts/changed-feature-flags' - 'scripts/failed_tests.rb' - 'scripts/lib/glfm/parse_examples.rb' @@ -83,14 +81,3 @@ Performance/RegexpMatch: - 'scripts/qa/testcases-check' - 'scripts/trigger-build.rb' - 'sidekiq_cluster/cli.rb' - - 'spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb' - - 'spec/mailers/emails/in_product_marketing_spec.rb' - - 'spec/spec_helper.rb' - - 'spec/support/capybara.rb' - - 'spec/support/helpers/test_env.rb' - - 'spec/support/shared_contexts/features/integrations/integrations_shared_context.rb' - - 'spec/support/shared_examples/features/discussion_comments_shared_example.rb' - - 'spec/tooling/quality/test_level_spec.rb' - - 'tooling/danger/analytics_instrumentation.rb' - - 'tooling/danger/database_dictionary.rb' - - 'tooling/danger/specs/feature_category_suggestion.rb' diff --git a/rubocop/cop/project_path_helper.rb b/rubocop/cop/project_path_helper.rb index 104a352949f6ca5ad6fb903d6c9c594dbbcaf5be..f053c9a01b7a8576b85db218b3c65d5a488ae914 100644 --- a/rubocop/cop/project_path_helper.rb +++ b/rubocop/cop/project_path_helper.rb @@ -12,7 +12,7 @@ class ProjectPathHelper < RuboCop::Cop::Base METHOD_NAME_PATTERN = /\A([a-z_]+_)?namespace_project(?:_[a-z_]+)?_(?:url|path)\z/.freeze def on_send(node) - return unless method_name(node).to_s =~ METHOD_NAME_PATTERN + return unless METHOD_NAME_PATTERN.match?(method_name(node).to_s) namespace_expr, project_expr = arguments(node) return unless namespace_expr && project_expr diff --git a/rubocop/cop/qa/selector_usage.rb b/rubocop/cop/qa/selector_usage.rb index d615bd2926c9e3e210bf4cad76a810ee2a06b53f..c17f642bd06cc3821820c36fd7245e910d93990d 100644 --- a/rubocop/cop/qa/selector_usage.rb +++ b/rubocop/cop/qa/selector_usage.rb @@ -27,7 +27,7 @@ def on_str(node) return if in_qa_file?(node) return unless in_spec?(node) - add_offense(node, message: MESSAGE % node.value) if SELECTORS =~ node.value + add_offense(node, message: MESSAGE % node.value) if SELECTORS.match?(node.value) rescue StandardError # catch all errors and ignore them. # without this catch-all rescue, rubocop will fail diff --git a/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb b/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb index 05b67a8a93f30e9fd09d3f7058691150303da9c5..cc329c48c5f09f42c7a59631f575264c84016b6f 100644 --- a/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb +++ b/spec/lib/gitlab/cluster/mixins/puma_cluster_spec.rb @@ -98,7 +98,7 @@ def wait_for_output(process, output, timeout:) loop do line = process.readline puts "PUMA_DEBUG: #{line}" if ENV['PUMA_DEBUG'] - break if line =~ output + break if line.match?(output) end end end diff --git a/spec/mailers/emails/in_product_marketing_spec.rb b/spec/mailers/emails/in_product_marketing_spec.rb index 5419c9e6798f33a6933ed184dd8932f00ee9fb29..2d332dd99d696bef0b5c1a73a7096d48ad5f7657 100644 --- a/spec/mailers/emails/in_product_marketing_spec.rb +++ b/spec/mailers/emails/in_product_marketing_spec.rb @@ -80,7 +80,7 @@ is_expected.to have_body_text(message.subtitle) is_expected.to have_body_text(CGI.unescapeHTML(message.cta_link)) - if track =~ /(create|verify)/ + if /create|verify/.match?(track) is_expected.to have_body_text(message.invite_text) is_expected.to have_body_text(CGI.unescapeHTML(message.invite_link)) else diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 18dba7e68ad382cade8f5f37d41c3f14b05b4e4d..332674e4c8f9acff18aeab0ed30b84dfa93588ed 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -150,7 +150,7 @@ # Admin controller specs get auto admin mode enabled since they are # protected by the 'EnforcesAdminAuthentication' concern - metadata[:enable_admin_mode] = true if location =~ %r{(ee)?/spec/controllers/admin/} + metadata[:enable_admin_mode] = true if %r{(ee)?/spec/controllers/admin/}.match?(location) end config.define_derived_metadata(file_path: %r{(ee)?/spec/.+_docs\.rb\z}) do |metadata| diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index c7b2a03fde231c4aa8b7b30ddb33a185c2855050..6bf828ce0393a871061d3e826a4b69dbf62da56d 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -5,6 +5,7 @@ require 'capybara/rspec' require 'capybara-screenshot/rspec' require 'selenium-webdriver' +require 'gitlab/utils/all' # Give CI some extra time timeout = ENV['CI'] || ENV['CI_SERVER'] ? 30 : 10 @@ -117,7 +118,7 @@ options.add_argument("--window-size=#{CAPYBARA_WINDOW_SIZE.join(',')}") # Run headless by default unless WEBDRIVER_HEADLESS specified - options.add_argument("--headless") unless ENV['WEBDRIVER_HEADLESS'] =~ /^(false|no|0)$/i + options.add_argument("--headless") unless Gitlab::Utils.to_boolean(ENV['WEBDRIVER_HEADLESS'], default: false) Capybara::Selenium::Driver.new( app, diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index da4954c1a5f06a08fb0f7826b02b8d811f4242bd..b95adb3fe4dfbbed6be3a8ef1cf066697e392c26 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -523,7 +523,7 @@ def component_ahead_of_target?(component_folder, expected_version) def component_matches_git_sha?(component_folder, expected_version) # Not a git SHA, so return early - return false unless expected_version =~ ::Gitlab::Git::COMMIT_ID + return false unless ::Gitlab::Git::COMMIT_ID.match?(expected_version) return false unless Dir.exist?(component_folder) diff --git a/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb index 21d9dccbb8d6a67c1afb2fc288179b35f86693d9..8c17136b1e2dbb6aec6e597770dbf215057a1f7c 100644 --- a/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb +++ b/spec/support/shared_contexts/features/integrations/integrations_shared_context.rb @@ -56,7 +56,7 @@ hash.merge!(k => 'key:value') elsif integration == 'packagist' && k == :server hash.merge!(k => 'https://packagist.example.com') - elsif k =~ /^(.*_url|url|webhook)/ + elsif /^(.*_url|url|webhook)/.match?(k) hash.merge!(k => "http://example.com") elsif integration_klass.method_defined?("#{k}?") hash.merge!(k => true) diff --git a/spec/support/shared_examples/features/discussion_comments_shared_example.rb b/spec/support/shared_examples/features/discussion_comments_shared_example.rb index d6f1efc09fcdc4577d66f6348140869642ba1772..ac8055138d76002165cf73af65bfb1ffebf04fa7 100644 --- a/spec/support/shared_examples/features/discussion_comments_shared_example.rb +++ b/spec/support/shared_examples/features/discussion_comments_shared_example.rb @@ -284,7 +284,7 @@ def submit_reply(text) expect(new_comment).to have_css('.discussion-with-resolve-btn') end - if resource_name =~ /(issue|merge request)/ + if /(issue|merge request)/.match?(resource_name) it 'can be replied to' do submit_reply('some text') @@ -373,7 +373,7 @@ def submit_reply(text) expect(page).not_to have_selector menu_selector end - if resource_name =~ /(issue|merge request)/ + if /(issue|merge request)/.match?(resource_name) it 'updates the close button text' do expect(find(close_selector)).to have_content "Comment & close #{resource_name}" end @@ -402,7 +402,7 @@ def submit_reply(text) end end - if resource_name =~ /(issue|merge request)/ + if /(issue|merge request)/.match?(resource_name) describe "on a closed #{resource_name}" do before do find("#{form_selector} .js-note-target-close").click diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb index a7e4e42206a25c8ec197c2e273e13501db5985e7..6ccd2e46f7bb327ddcd4305d41d3fdc0dac9e885 100644 --- a/spec/tooling/quality/test_level_spec.rb +++ b/spec/tooling/quality/test_level_spec.rb @@ -238,7 +238,7 @@ it 'ensures all spec/ folders are covered by a test level' do Dir['{,ee/}spec/**/*/'].each do |path| - next if path =~ %r{\A(ee/)?spec/(benchmarks|docs_screenshots|fixtures|frontend_integration|support)/} + next if %r{\A(ee/)?spec/(benchmarks|docs_screenshots|fixtures|frontend_integration|support)/}.match?(path) expect { subject.level_for(path) }.not_to raise_error end diff --git a/tooling/danger/analytics_instrumentation.rb b/tooling/danger/analytics_instrumentation.rb index 767ae8dfb4c9874bc2c9ffacfb67f7394fdb5f74..69cc30f51fbe7f9632fd7bb48ee438eb3eaf21a9 100644 --- a/tooling/danger/analytics_instrumentation.rb +++ b/tooling/danger/analytics_instrumentation.rb @@ -77,7 +77,7 @@ def convert_to_table(items) def metric_scope_affected select_models(helper.modified_files).each_with_object(Hash.new { |h, k| h[k] = [] }) do |file_name, matched_files| helper.changed_lines(file_name).each do |mod_line, _i| - next unless mod_line =~ /^\+\s+scope :\w+/ + next unless /^\+\s+scope :\w+/.match?(mod_line) affected_scope = mod_line.match(/:\w+/) next if affected_scope.nil? diff --git a/tooling/danger/database_dictionary.rb b/tooling/danger/database_dictionary.rb index 8776532ff84c0314dff184b19ba9ad2029016907..2ea937efd7378372afce68454fb26e3e56b778ce 100644 --- a/tooling/danger/database_dictionary.rb +++ b/tooling/danger/database_dictionary.rb @@ -14,7 +14,7 @@ module DatabaseDictionary def database_dictionary_files(change_type:) files = helper.public_send("#{change_type}_files") # rubocop:disable GitlabSecurity/PublicSend - files.filter_map { |path| Found.new(path) if path =~ DICTIONARY_PATH_REGEXP } + files.filter_map { |path| Found.new(path) if DICTIONARY_PATH_REGEXP.match?(path) } end class Found diff --git a/tooling/danger/specs/feature_category_suggestion.rb b/tooling/danger/specs/feature_category_suggestion.rb index 5acf73c895621f8df0bae3b4386b584d3cbe176a..00cb99f368bfc7fc31ae8bc69743686248335264 100644 --- a/tooling/danger/specs/feature_category_suggestion.rb +++ b/tooling/danger/specs/feature_category_suggestion.rb @@ -18,7 +18,7 @@ def suggest changed_lines = helper.changed_lines(filename) changed_lines.each do |changed_line| - next unless changed_line =~ RSPEC_TOP_LEVEL_DESCRIBE_REGEX + next unless RSPEC_TOP_LEVEL_DESCRIBE_REGEX.match?(changed_line) line_number = file_lines.find_index(changed_line.delete_prefix('+')) next unless line_number