Browse Source

Replace gsub with tr, delete, or squeeze (#34161).


git-svn-id: http://svn.redmine.org/redmine/trunk@20176 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.2.0
Go MAEDA 3 years ago
parent
commit
78dfef0978

+ 0
- 22
.rubocop_todo.yml View File

@@ -564,11 +564,6 @@ Performance/RedundantMatch:
- 'lib/redmine/wiki_formatting/textile/formatter.rb'
- 'lib/redmine/wiki_formatting/textile/redcloth3.rb'

# Cop supports --auto-correct.
Performance/Squeeze:
Exclude:
- 'test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb'

# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/StringInclude:
@@ -578,23 +573,6 @@ Performance/StringInclude:
- 'test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb'
- 'test/unit/lib/redmine/wiki_formatting/macros_test.rb'

# Cop supports --auto-correct.
Performance/StringReplacement:
Exclude:
- 'app/helpers/application_helper.rb'
- 'app/helpers/imports_helper.rb'
- 'app/helpers/settings_helper.rb'
- 'lib/redmine/core_ext/string/conversions.rb'
- 'lib/redmine/wiki_formatting/textile/redcloth3.rb'
- 'test/functional/repositories_cvs_controller_test.rb'
- 'test/functional/repositories_git_controller_test.rb'
- 'test/helpers/application_helper_test.rb'
- 'test/integration/repositories_git_test.rb'
- 'test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb'
- 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb'
- 'test/unit/repository_cvs_test.rb'
- 'test/unit/repository_git_test.rb'

# Cop supports --auto-correct.
Performance/Sum:
Exclude:

+ 1
- 1
app/helpers/application_helper.rb View File

@@ -895,7 +895,7 @@ module ApplicationHelper
# search for the picture in attachments
if found = Attachment.latest_attach(attachments, CGI.unescape(filename))
image_url = download_named_attachment_url(found, found.filename, :only_path => only_path)
desc = found.description.to_s.gsub('"', '')
desc = found.description.to_s.delete('"')
if !desc.blank? && alttext.blank?
alt = " title=\"#{desc}\" alt=\"#{desc}\""
end

+ 1
- 1
app/helpers/imports_helper.rb View File

@@ -46,7 +46,7 @@ module ImportsHelper
# Returns the options for the date_format setting
def date_format_options
Import::DATE_FORMATS.map do |f|
format = f.gsub('%', '').gsub(/[dmY]/) do
format = f.delete('%').gsub(/[dmY]/) do
{'d' => 'DD', 'm' => 'MM', 'Y' => 'YYYY'}[$&]
end
[format, f]

+ 1
- 1
app/helpers/settings_helper.rb View File

@@ -209,7 +209,7 @@ module SettingsHelper
def date_format_setting_options(locale)
Setting::DATE_FORMATS.map do |f|
today = ::I18n.l(User.current.today, :locale => locale, :format => f)
format = f.gsub('%', '').gsub(/[dmY]/) do
format = f.delete('%').gsub(/[dmY]/) do
{'d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy'}[$&]
end
["#{today} (#{format})", f]

+ 1
- 1
lib/redmine/core_ext/string/conversions.rb View File

@@ -38,7 +38,7 @@ module Redmine
s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}i) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] }
end
# 2,5 => 2.5
s.gsub!(',', '.')
s.tr!(',', '.')
begin; Kernel.Float(s); rescue; nil; end
end
end

+ 1
- 1
lib/redmine/wiki_formatting/textile/redcloth3.rb View File

@@ -1016,7 +1016,7 @@ class RedCloth3 < String
def clean_white_space( text )
# normalize line breaks
text.gsub!( /\r\n/, "\n" )
text.gsub!( /\r/, "\n" )
text.tr!( "\r", "\n" )
text.gsub!( /\t/, ' ' )
text.gsub!( /^ +$/, '' )
text.gsub!( /\n{3,}/, "\n\n" )

+ 1
- 1
test/functional/repositories_cvs_controller_test.rb View File

@@ -26,7 +26,7 @@ class RepositoriesCvsControllerTest < Redmine::RepositoryControllerTest
:repositories, :enabled_modules

REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
# CVS module
MODULE_NAME = 'test'
PRJ_ID = 3

+ 1
- 1
test/functional/repositories_git_controller_test.rb View File

@@ -26,7 +26,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
:repositories, :enabled_modules

REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
PRJ_ID = 3
NUM_REV = 28


+ 4
- 4
test/helpers/application_helper_test.rb View File

@@ -1423,7 +1423,7 @@ class ApplicationHelperTest < Redmine::HelperTest
'</ul>'

@project = Project.find(1)
assert textilizable(raw).gsub("\n", "").include?(expected)
assert textilizable(raw).delete("\n").include?(expected)
end

def test_table_of_content_should_generate_unique_anchors
@@ -1447,7 +1447,7 @@ class ApplicationHelperTest < Redmine::HelperTest
'</li>' +
'</ul>'
@project = Project.find(1)
result = textilizable(raw).gsub("\n", "")
result = textilizable(raw).delete("\n")
assert_include expected, result
assert_include '<a name="Subtitle">', result
assert_include '<a name="Subtitle-2">', result
@@ -1468,7 +1468,7 @@ class ApplicationHelperTest < Redmine::HelperTest
'<li><a href="#Child-page-1">Child page 1</a></li>' +
'</ul>'
@project = Project.find(1)
assert textilizable(raw).gsub("\n", "").include?(expected)
assert textilizable(raw).delete("\n").include?(expected)
end

def test_toc_with_textile_formatting_should_be_parsed
@@ -1519,7 +1519,7 @@ class ApplicationHelperTest < Redmine::HelperTest
:edit_section_links =>
{:controller => 'wiki', :action => 'edit',
:project_id => '1', :id => 'Test'}
).gsub("\n", "")
).delete("\n")
# heading that contains inline code
assert_match(
Regexp.new('<div class="contextual heading-2" title="Edit this section" id="section-4">' +

+ 1
- 1
test/integration/repositories_git_test.rb View File

@@ -24,7 +24,7 @@ class RepositoriesGitTest < Redmine::IntegrationTest
:repositories, :enabled_modules

REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
PRJ_ID = 3
NUM_REV = 28


+ 1
- 1
test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb View File

@@ -21,7 +21,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__)

class BazaarAdapterTest < ActiveSupport::TestCase
REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
REPOSITORY_PATH.gsub!(/\/+/, '/')
REPOSITORY_PATH.squeeze!('/')

if File.directory?(REPOSITORY_PATH)
def setup

+ 1
- 1
test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb View File

@@ -21,7 +21,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__)

class CvsAdapterTest < ActiveSupport::TestCase
REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
MODULE_NAME = 'test'

if File.directory?(REPOSITORY_PATH)

+ 1
- 1
test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb View File

@@ -85,7 +85,7 @@ class MercurialAdapterTest < ActiveSupport::TestCase
[REPOSITORY_PATH, REPOSITORY_PATH + "/",
REPOSITORY_PATH + "//"].each do |repo|
adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
repo_path = adp.info.root_url.gsub(/\\/, "/")
repo_path = adp.info.root_url.tr('\\', "/")
assert_equal REPOSITORY_PATH, repo_path
assert_equal '39', adp.info.lastrev.revision
assert_equal '04aed9840e9266e535f5f20f7e42c9f9f84f9cf4', adp.info.lastrev.scmid

+ 1
- 1
test/unit/repository_cvs_test.rb View File

@@ -25,7 +25,7 @@ class RepositoryCvsTest < ActiveSupport::TestCase
include Redmine::I18n

REPOSITORY_PATH = repository_path('cvs')
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
# CVS module
MODULE_NAME = 'test'
CHANGESETS_NUM = 7

+ 2
- 2
test/unit/repository_git_test.rb View File

@@ -25,10 +25,10 @@ class RepositoryGitTest < ActiveSupport::TestCase
include Redmine::I18n

REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?

REPOSITORY_UTF8_PATH = Rails.root.join('tmp/test/git_utf8_repository').to_s
REPOSITORY_UTF8_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
REPOSITORY_UTF8_PATH.tr!('/', "\\") if Redmine::Platform.mswin?

NUM_REV = 28
NUM_HEAD = 8

Loading…
Cancel
Save