Skip to content

Commit 5180fa2

Browse files
committed
Use RuboCop Performance for development
This commit uses RuboCop Performance for development and fixes the following offenses. ```console % bundle exec rake bundle exec rubocop Inspecting 116 files ...C................................................................................................................ Offenses: tasks/cops_documentation.rake:60:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "\n".dup ^^^^^^^^ tasks/cops_documentation.rake:67:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "\n".dup ^^^^^^^^ tasks/cops_documentation.rake:74:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "#### #{title}\n".dup ^^^^^^^^^^^^^^^^^^^^^ tasks/cops_documentation.rake:80:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "```ruby\n".dup ^^^^^^^^^^^^^^^ tasks/cops_documentation.rake:171:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "# #{department}\n".dup ^^^^^^^^^^^^^^^^^^^^^^^ tasks/cops_documentation.rake:209:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "#### Department [#{type_title}](#{filename})\n\n".dup ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tasks/cops_documentation.rake:222:15: C: Performance/UnfreezeString: Use unary plus to get an unfrozen string literal. content = "<!-- START_COP_LIST -->\n".dup ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 116 files inspected, 7 offenses detected rake aborted! ```
1 parent a32a3b3 commit 5180fa2

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
inherit_from: .rubocop_todo.yml
44
require:
55
- rubocop/cop/internal_affairs
6+
- rubocop-performance
67
- rubocop-rspec
78

89
AllCops:

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ gemspec
99
gem 'rake'
1010
gem 'rspec'
1111
gem 'rubocop', github: 'rubocop-hq/rubocop'
12+
gem 'rubocop-performance', '~> 1.3.0'
1213
gem 'rubocop-rspec', '~> 1.29.0'
1314
gem 'yard', '~> 0.9'

tasks/cops_documentation.rake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ task generate_cops_documentation: :yard_for_generate_documentation do
5757
# rubocop:enable Metrics/MethodLength
5858

5959
def h2(title)
60-
content = "\n".dup
60+
content = +"\n"
6161
content << "## #{title}\n"
6262
content << "\n"
6363
content
6464
end
6565

6666
def h3(title)
67-
content = "\n".dup
67+
content = +"\n"
6868
content << "### #{title}\n"
6969
content << "\n"
7070
content
7171
end
7272

7373
def h4(title)
74-
content = "#### #{title}\n".dup
74+
content = +"#### #{title}\n"
7575
content << "\n"
7676
content
7777
end
7878

7979
def code_example(ruby_code)
80-
content = "```ruby\n".dup
80+
content = +"```ruby\n"
8181
content << ruby_code.text
8282
.gsub('@good', '# good').gsub('@bad', '# bad').strip
8383
content << "\n```\n"
@@ -168,7 +168,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
168168
end
169169
return if selected_cops.empty?
170170

171-
content = "# #{department}\n".dup
171+
content = +"# #{department}\n"
172172
selected_cops.each do |cop|
173173
content << print_cop_with_doc(cop, config)
174174
end
@@ -206,7 +206,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
206206

207207
type_title = department[0].upcase + department[1..-1]
208208
filename = "cops_#{department.downcase}.md"
209-
content = "#### Department [#{type_title}](#{filename})\n\n".dup
209+
content = +"#### Department [#{type_title}](#{filename})\n\n"
210210
selected_cops.each do |cop|
211211
anchor = cop.cop_name.sub('/', '').downcase
212212
content << "* [#{cop.cop_name}](#{filename}##{anchor})\n"
@@ -219,7 +219,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
219219
def print_table_of_contents(cops)
220220
path = "#{Dir.pwd}/manual/cops.md"
221221
original = File.read(path)
222-
content = "<!-- START_COP_LIST -->\n".dup
222+
content = +"<!-- START_COP_LIST -->\n"
223223

224224
content << table_contents(cops)
225225

0 commit comments

Comments
 (0)