summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Shea <connor.james.shea@gmail.com>2016-04-27 18:22:46 -0600
committerConnor Shea <connor.james.shea@gmail.com>2016-05-10 18:34:15 -0600
commit4995302df64b71846370aa80f5b12a2d73112421 (patch)
treed6e0667f4f0399a7a13f17e54fa1860b03a588ed
parent4a47470febe34bf67e84a2904422626caa64224e (diff)
downloadgitlab-ce-4995302df64b71846370aa80f5b12a2d73112421.tar.gz
Enable the StringReplacement cop.
Also fix one use of `gsub` that would be faster as `delete`. Use `tr` instead of `gsub` when you are replacing the same number of characters. Use `delete` instead of `gsub` when you are deleting characters.
-rw-r--r--.rubocop.yml3
-rw-r--r--lib/gitlab/diff/parser.rb2
2 files changed, 3 insertions, 2 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 9f179efa3ce..c96c7123c16 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -990,11 +990,12 @@ Performance/RedundantSortBy:
# string.
Performance/StartWith:
Enabled: false
+
# Use `tr` instead of `gsub` when you are replacing the same number of
# characters. Use `delete` instead of `gsub` when you are deleting
# characters.
Performance/StringReplacement:
- Enabled: false
+ Enabled: true
# TODO: Enable TimesMap Cop.
# Checks for `.times.map` calls.
diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb
index d0815fc7eea..6fe7faa547a 100644
--- a/lib/gitlab/diff/parser.rb
+++ b/lib/gitlab/diff/parser.rb
@@ -18,7 +18,7 @@ module Gitlab
@lines.each do |line|
next if filename?(line)
- full_line = line.gsub(/\n/, '')
+ full_line = line.delete("\n")
if line.match(/^@@ -/)
type = "match"