Skip to content

Commit b7ac06b

Browse files
committed
Remove redundant to_s suggestion from offense message for Rails/FilePath
Follow up #968. `to_s` should be called implicitly when string interpolated.
1 parent 594ed90 commit b7ac06b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/rubocop/cop/rails/file_path.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def string_with_slash?(node)
106106
def register_offense(node, require_to_s:)
107107
line_range = node.loc.column...node.loc.last_column
108108
source_range = source_range(processed_source.buffer, node.first_line, line_range)
109+
require_to_s = false if node.dstr_type?
110+
109111
message = build_message(require_to_s)
110112

111113
add_offense(source_range, message: message)

spec/rubocop/cop/rails/file_path_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
it 'registers an offense' do
8484
expect_offense(<<~'RUBY')
8585
"#{Rails.root}/app/models/goober"
86-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`.
86+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to')`.
8787
RUBY
8888
end
8989
end
@@ -92,7 +92,7 @@
9292
it 'registers an offense' do
9393
expect_offense(<<~'RUBY')
9494
system "rm -rf #{Rails.root}/foo/bar"
95-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`.
95+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to')`.
9696
RUBY
9797
end
9898
end
@@ -101,7 +101,7 @@
101101
it 'registers an offense' do
102102
expect_offense(<<~'RUBY')
103103
"#{Rails.root.join('tmp', user.id, 'icon')}.png"
104-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to').to_s`.
104+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path/to')`.
105105
RUBY
106106
end
107107
end
@@ -211,7 +211,7 @@
211211
it 'registers an offense' do
212212
expect_offense(<<~'RUBY')
213213
"#{Rails.root}/app/models/goober"
214-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`.
214+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to')`.
215215
RUBY
216216
end
217217
end
@@ -220,7 +220,7 @@
220220
it 'registers an offense' do
221221
expect_offense(<<~'RUBY')
222222
system "rm -rf #{Rails.root}/foo/bar"
223-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`.
223+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to')`.
224224
RUBY
225225
end
226226
end
@@ -229,7 +229,7 @@
229229
it 'registers an offense' do
230230
expect_offense(<<~'RUBY')
231231
"#{Rails.root.join('tmp', user.id, 'icon')}.png"
232-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to').to_s`.
232+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Rails.root.join('path', 'to')`.
233233
RUBY
234234
end
235235
end

0 commit comments

Comments
 (0)