From 15c89a1669d9e4b08865c288bf5b3d59bc69e322 Mon Sep 17 00:00:00 2001
From: Archish Thakkar <archishthakkar@gmail.com>
Date: Fri, 17 May 2024 17:55:09 +0000
Subject: [PATCH] Fix for Performance/StringReplacement
 Naming/HeredocDelimiterCase

---
 .../naming/heredoc_delimiter_case.yml         |  9 ---------
 .../performance/string_replacement.yml        |  8 --------
 ee/app/models/saml_provider.rb                |  2 +-
 lib/gitlab/uploads/migration_helper.rb        |  2 +-
 .../parser/atlassian_document_format.rb       |  2 +-
 spec/lib/gitlab/diff/parser_spec.rb           |  4 ++--
 spec/lib/json_web_token/rsa_token_spec.rb     |  4 ++--
 spec/models/commit_spec.rb                    | 12 +++++------
 spec/support/helpers/repo_helpers.rb          | 20 +++++++++----------
 spec/support/helpers/seed_repo.rb             |  4 ++--
 10 files changed, 25 insertions(+), 42 deletions(-)
 delete mode 100644 .rubocop_todo/naming/heredoc_delimiter_case.yml
 delete mode 100644 .rubocop_todo/performance/string_replacement.yml

diff --git a/.rubocop_todo/naming/heredoc_delimiter_case.yml b/.rubocop_todo/naming/heredoc_delimiter_case.yml
deleted file mode 100644
index 2d2337b82ee2a..0000000000000
--- a/.rubocop_todo/naming/heredoc_delimiter_case.yml
+++ /dev/null
@@ -1,9 +0,0 @@
----
-# Cop supports --autocorrect.
-Naming/HeredocDelimiterCase:
-  Exclude:
-    - 'spec/lib/gitlab/diff/parser_spec.rb'
-    - 'spec/lib/json_web_token/rsa_token_spec.rb'
-    - 'spec/models/commit_spec.rb'
-    - 'spec/support/helpers/repo_helpers.rb'
-    - 'spec/support/helpers/seed_repo.rb'
diff --git a/.rubocop_todo/performance/string_replacement.yml b/.rubocop_todo/performance/string_replacement.yml
deleted file mode 100644
index db22bba0897f3..0000000000000
--- a/.rubocop_todo/performance/string_replacement.yml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-# Cop supports --autocorrect.
-Performance/StringReplacement:
-  Details: grace period
-  Exclude:
-    - 'ee/app/models/saml_provider.rb'
-    - 'lib/gitlab/uploads/migration_helper.rb'
-    - 'lib/kramdown/parser/atlassian_document_format.rb'
diff --git a/ee/app/models/saml_provider.rb b/ee/app/models/saml_provider.rb
index 269d27480ff5c..586016a3dcade 100644
--- a/ee/app/models/saml_provider.rb
+++ b/ee/app/models/saml_provider.rb
@@ -118,6 +118,6 @@ def set_defaults
   end
 
   def strip_left_to_right_chars(input)
-    input&.gsub(/\u200E/, '')
+    input&.delete("\u200E")
   end
 end
diff --git a/lib/gitlab/uploads/migration_helper.rb b/lib/gitlab/uploads/migration_helper.rb
index 712512d0e028b..3804b7139cb47 100644
--- a/lib/gitlab/uploads/migration_helper.rb
+++ b/lib/gitlab/uploads/migration_helper.rb
@@ -28,7 +28,7 @@ def batch_size
       end
 
       def prepare_variables(args, logger)
-        @mounted_as     = args.mounted_as&.gsub(':', '')
+        @mounted_as     = args.mounted_as&.delete(':')
         @uploader_class = args.uploader_class
         @model_class    = args.model_class&.constantize
         @logger         = logger
diff --git a/lib/kramdown/parser/atlassian_document_format.rb b/lib/kramdown/parser/atlassian_document_format.rb
index 5a481042b158f..0b259058f01a7 100644
--- a/lib/kramdown/parser/atlassian_document_format.rb
+++ b/lib/kramdown/parser/atlassian_document_format.rb
@@ -218,7 +218,7 @@ def process_mention(element, ast_node)
         # a valid username in our system.  This gives us an
         # opportunity to replace it later. Mention name can have
         # spaces, so double quote it
-        mention_text = ast_node.dig('attrs', 'text')&.gsub('@', '')
+        mention_text = ast_node.dig('attrs', 'text')&.delete('@')
         mention_text = %("#{mention_text}") if mention_text&.include?(' ')
         mention_text = %(@adf-mention:#{mention_text})
 
diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb
index c8069f82f0475..0b9d9f44d4708 100644
--- a/spec/lib/gitlab/diff/parser_spec.rb
+++ b/spec/lib/gitlab/diff/parser_spec.rb
@@ -12,7 +12,7 @@
 
   describe '#parse' do
     let(:diff) do
-      <<eos
+      <<EOS
 --- a/files/ruby/popen.rb
 +++ b/files/ruby/popen.rb
 @@ -6,12 +6,18 @@ module Popen
@@ -45,7 +45,7 @@ def popen(cmd, path=nil)
      Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|
        @cmd_output << stdout.read
        @cmd_output << stderr.read
-eos
+EOS
     end
 
     before do
diff --git a/spec/lib/json_web_token/rsa_token_spec.rb b/spec/lib/json_web_token/rsa_token_spec.rb
index fd553eb181ead..81f583322575f 100644
--- a/spec/lib/json_web_token/rsa_token_spec.rb
+++ b/spec/lib/json_web_token/rsa_token_spec.rb
@@ -2,7 +2,7 @@
 
 RSpec.describe JSONWebToken::RSAToken do
   let_it_be(:rsa_key) do
-    OpenSSL::PKey::RSA.new <<-eos.strip_heredoc
+    OpenSSL::PKey::RSA.new <<-EOS.strip_heredoc
       -----BEGIN RSA PRIVATE KEY-----
       MIIBOgIBAAJBAMA5sXIBE0HwgIB40iNidN4PGWzOyLQK0bsdOBNgpEXkDlZBvnak
       OUgAPF+rME4PB0Yl415DabUI40T5UNmlwxcCAwEAAQJAZtY2pSwIFm3JAXIh0cZZ
@@ -12,7 +12,7 @@
       A6PRG/PSTpQtAiBxtBg6zdf+JC3GH3zt/dA0/10tL4OF2wORfYQghRzyYQIhAL2l
       0ZQW+yLIZAGrdBFWYEAa52GZosncmzBNlsoTgwE4
       -----END RSA PRIVATE KEY-----
-    eos
+    EOS
   end
 
   let(:rsa_token) { described_class.new(nil) }
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index a098ac2a4ab0e..47fd1222fece8 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -408,10 +408,10 @@
     end
 
     it "does not truncates a message with a newline after 80 but less 100 characters" do
-      message = <<eos
+      message = <<EOS
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
 Vivamus egestas lacinia lacus, sed rutrum mauris.
-eos
+EOS
 
       allow(commit).to receive(:safe_message).and_return(message)
       expect(commit.title).to eq(message.split("\n").first)
@@ -460,20 +460,20 @@
     end
 
     it 'returns description of commit message if title less than 100 characters' do
-      message = <<eos
+      message = <<EOS
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit.
 Vivamus egestas lacinia lacus, sed rutrum mauris.
-eos
+EOS
 
       allow(commit).to receive(:safe_message).and_return(message)
       expect(commit.description).to eq('Vivamus egestas lacinia lacus, sed rutrum mauris.')
     end
 
     it 'returns full commit message if commit title more than 100 characters' do
-      message = <<eos
+      message = <<EOS
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.
 Vivamus egestas lacinia lacus, sed rutrum mauris.
-eos
+EOS
 
       allow(commit).to receive(:safe_message).and_return(message)
       expect(commit.description).to eq(message)
diff --git a/spec/support/helpers/repo_helpers.rb b/spec/support/helpers/repo_helpers.rb
index b51afaac40e78..5578e6350cf65 100644
--- a/spec/support/helpers/repo_helpers.rb
+++ b/spec/support/helpers/repo_helpers.rb
@@ -19,14 +19,14 @@ def sample_blob
     OpenStruct.new(
       oid: '5f53439ca4b009096571d3c8bc3d09d30e7431b3',
       path: "files/js/commit.js.coffee",
-      data: <<eos
+      data: <<EOS
 class Commit
   constructor: ->
     $('.files .diff-file').each ->
       new CommitFile(this)
 
 @Commit = Commit
-eos
+EOS
     )
   end
 
@@ -42,10 +42,10 @@ def sample_commit
       line_code_path: 'files/ruby/popen.rb',
       del_line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13',
       referenced_by: [],
-      message: <<eos
+      message: <<EOS
 Change some files
 Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-eos
+EOS
     )
   end
 
@@ -58,7 +58,7 @@ def another_sample_commit
       author_email: "sytse@gitlab.com",
       files_changed_count: 1,
       referenced_by: [],
-      message: <<eos
+      message: <<EOS
 Add directory structure for tree_helper spec
 
 This directory structure is needed for a testing the method flatten_tree(tree) in the TreeHelper module
@@ -66,7 +66,7 @@ def another_sample_commit
 See [merge request #275](https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/275#note_732774)
 
 See merge request !2
-eos
+EOS
     )
   end
 
@@ -77,10 +77,10 @@ def sample_big_commit
       author_full_name: "Dmitriy Zaporozhets",
       author_email: "dmitriy.zaporozhets@gmail.com",
       referenced_by: [],
-      message: <<eos
+      message: <<EOS
 Files, encoding and much more
 Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-eos
+EOS
     )
   end
 
@@ -93,10 +93,10 @@ def sample_image_commit
       old_blob_id: '33f3729a45c02fc67d00adb1b8bca394b0e761d9',
       new_blob_id: '2f63565e7aac07bcdadb654e253078b727143ec4',
       referenced_by: [],
-      message: <<eos
+      message: <<EOS
 Modified image
 Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-eos
+EOS
     )
   end
 
diff --git a/spec/support/helpers/seed_repo.rb b/spec/support/helpers/seed_repo.rb
index b0bd0dfb60e75..b6afa46d21760 100644
--- a/spec/support/helpers/seed_repo.rb
+++ b/spec/support/helpers/seed_repo.rb
@@ -113,7 +113,7 @@ module Repo
   module RubyBlob
     ID = "7e3e39ebb9b2bf433b4ad17313770fbe4051649c"
     NAME = "popen.rb"
-    CONTENT = <<-eos
+    CONTENT = <<-EOS
 require 'fileutils'
 require 'open3'
 
@@ -151,6 +151,6 @@ def popen(cmd, path=nil)
     return @cmd_output, @cmd_status
   end
 end
-    eos
+    EOS
   end
 end
-- 
GitLab