Commit 6d0654f3 authored by Siddharth Asthana's avatar Siddharth Asthana

Resolve Performance/DeletePrefix rubocop offenses

Changelog: other
EE: true
parent 0e060c73
...@@ -30,7 +30,7 @@ module SubmoduleHelper ...@@ -30,7 +30,7 @@ module SubmoduleHelper
end end
end end
namespace.sub!(%r{\A/}, '') namespace.delete_prefix!('/')
project.rstrip! project.rstrip!
project.delete_suffix!('.git') project.delete_suffix!('.git')
......
...@@ -173,7 +173,7 @@ module Gitlab ...@@ -173,7 +173,7 @@ module Gitlab
# https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols # https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols
# #
def remove_upload_pack_http_service_fragment_from(body) def remove_upload_pack_http_service_fragment_from(body)
body.gsub(/\A001e# service=git-upload-pack\n0000/, '') body.delete_prefix("001e# service=git-upload-pack\n0000")
end end
# See Uploading Data > HTTP(S) section at: # See Uploading Data > HTTP(S) section at:
...@@ -195,7 +195,7 @@ module Gitlab ...@@ -195,7 +195,7 @@ module Gitlab
# https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols # https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols
# #
def remove_receive_pack_http_service_fragment_from(body) def remove_receive_pack_http_service_fragment_from(body)
body.gsub(/\A001f# service=git-receive-pack\n0000/, '') body.delete_prefix("001f# service=git-receive-pack\n0000")
end end
def ensure_secondary! def ensure_secondary!
......
...@@ -180,7 +180,7 @@ module Banzai ...@@ -180,7 +180,7 @@ module Banzai
parts.pop if uri_type(request_path) != :tree parts.pop if uri_type(request_path) != :tree
path.sub!(%r{\A\./}, '') path.delete_prefix!('./')
while path.start_with?('../') while path.start_with?('../')
parts.pop parts.pop
......
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
def self.normalize_value(given_value) def self.normalize_value(given_value)
dummy_dn = "placeholder=#{given_value}" dummy_dn = "placeholder=#{given_value}"
normalized_dn = new(*dummy_dn).to_normalized_s normalized_dn = new(*dummy_dn).to_normalized_s
normalized_dn.sub(/\Aplaceholder=/, '') normalized_dn.delete_prefix('placeholder=')
end end
## ##
......
...@@ -37,7 +37,7 @@ module Gitlab ...@@ -37,7 +37,7 @@ module Gitlab
if was_embedded?(markdown) if was_embedded?(markdown)
moved_markdown moved_markdown
else else
moved_markdown.sub(/\A!/, "") moved_markdown.delete_prefix('!')
end end
end end
end end
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
# Ex. # Ex.
# Ref.extract_branch_name('refs/heads/master') #=> 'master' # Ref.extract_branch_name('refs/heads/master') #=> 'master'
def self.extract_branch_name(str) def self.extract_branch_name(str)
str.gsub(%r{\Arefs/heads/}, '') str.delete_prefix('refs/heads/')
end end
def initialize(repository, name, target, dereferenced_target) def initialize(repository, name, target, dereferenced_target)
......
...@@ -29,7 +29,7 @@ module Gitlab ...@@ -29,7 +29,7 @@ module Gitlab
end end
def project_path def project_path
URI.parse(preview).path.sub(%r{\A/}, '') URI.parse(preview).path.delete_prefix('/')
end end
def uri_encoded_project_path def uri_encoded_project_path
......
...@@ -98,7 +98,7 @@ module Gitlab ...@@ -98,7 +98,7 @@ module Gitlab
storages << { name: key, path: storage_paths[key] } storages << { name: key, path: storage_paths[key] }
end end
config = { socket_path: address.sub(/\Aunix:/, '') } config = { socket_path: address.delete_prefix('unix:') }
if Rails.env.test? if Rails.env.test?
socket_filename = options[:gitaly_socket] || "gitaly.socket" socket_filename = options[:gitaly_socket] || "gitaly.socket"
......
...@@ -8,7 +8,8 @@ module Gitlab ...@@ -8,7 +8,8 @@ module Gitlab
CUSTOM_DAY_AND_MONTH_LENGTH = { hours_per_day: 8, days_per_month: 20 }.freeze CUSTOM_DAY_AND_MONTH_LENGTH = { hours_per_day: 8, days_per_month: 20 }.freeze
def parse(string) def parse(string)
string = string.sub(/\A-/, '') negative_time = string.start_with?('-')
string = string.delete_prefix('-')
seconds = seconds =
begin begin
...@@ -19,7 +20,7 @@ module Gitlab ...@@ -19,7 +20,7 @@ module Gitlab
nil nil
end end
seconds *= -1 if seconds && Regexp.last_match seconds *= -1 if seconds && negative_time
seconds seconds
end end
......
...@@ -339,7 +339,7 @@ RSpec.describe Projects::ArtifactsController do ...@@ -339,7 +339,7 @@ RSpec.describe Projects::ArtifactsController do
def params def params
@params ||= begin @params ||= begin
base64_params = send_data.sub(/\Aartifacts\-entry:/, '') base64_params = send_data.delete_prefix('artifacts-entry:')
Gitlab::Json.parse(Base64.urlsafe_decode64(base64_params)) Gitlab::Json.parse(Base64.urlsafe_decode64(base64_params))
end end
end end
......
...@@ -67,7 +67,7 @@ RSpec.describe Gitlab::Gfm::UploadsRewriter do ...@@ -67,7 +67,7 @@ RSpec.describe Gitlab::Gfm::UploadsRewriter do
it 'does not rewrite plain links as embedded' do it 'does not rewrite plain links as embedded' do
embedded_link = image_uploader.markdown_link embedded_link = image_uploader.markdown_link
plain_image_link = embedded_link.sub(/\A!/, "") plain_image_link = embedded_link.delete_prefix('!')
text = "#{plain_image_link} and #{embedded_link}" text = "#{plain_image_link} and #{embedded_link}"
moved_text = described_class.new(text, old_project, user).rewrite(new_project) moved_text = described_class.new(text, old_project, user).rewrite(new_project)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment