Commit de5ae1bf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'string-replacement-cop' into 'master'

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.

See merge request !3960
parents c24cd968 4995302d
...@@ -990,11 +990,12 @@ Performance/RedundantSortBy: ...@@ -990,11 +990,12 @@ Performance/RedundantSortBy:
# string. # string.
Performance/StartWith: Performance/StartWith:
Enabled: false Enabled: false
# Use `tr` instead of `gsub` when you are replacing the same number of # Use `tr` instead of `gsub` when you are replacing the same number of
# characters. Use `delete` instead of `gsub` when you are deleting # characters. Use `delete` instead of `gsub` when you are deleting
# characters. # characters.
Performance/StringReplacement: Performance/StringReplacement:
Enabled: false Enabled: true
# TODO: Enable TimesMap Cop. # TODO: Enable TimesMap Cop.
# Checks for `.times.map` calls. # Checks for `.times.map` calls.
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
@lines.each do |line| @lines.each do |line|
next if filename?(line) next if filename?(line)
full_line = line.gsub(/\n/, '') full_line = line.delete("\n")
if line.match(/^@@ -/) if line.match(/^@@ -/)
type = "match" type = "match"
......
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