Skip to content

Commit db59655

Browse files
committed
[Fix #1066] Fix an error for Rails/FilePath
Fixes #1066. This PR fixes an error for `Rails/FilePath` when string interpolated `Rails.root` is followed by a message starting with `.`.
1 parent 34376e0 commit db59655

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1066](https://github.com/rubocop/rubocop-rails/issues/1066): Fix an error for `Rails/FilePath` when string interpolated `Rails.root` is followed by a message starting with `.`. ([@koic][])

lib/rubocop/cop/rails/file_path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def extract_rails_root_join_argument_source(node, rails_root_index)
233233
end
234234

235235
def extension_node?(node)
236-
node&.str_type? && node.source.start_with?('.')
236+
node&.str_type? && node.source.match?(/\A\.[A-Za-z]+/)
237237
end
238238
end
239239
end

spec/rubocop/cop/rails/file_path_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@
6464
end
6565
end
6666

67+
context 'when string interpolated `Rails.root` is followed by a message starting with `.`' do
68+
it 'does not register an offense' do
69+
expect_no_offenses(<<~'RUBY')
70+
"#{Rails.root}. a message"
71+
RUBY
72+
end
73+
end
74+
6775
context 'when using string interpolation without Rails.root' do
6876
it 'does not register an offense' do
6977
expect_no_offenses(<<~'RUBY')

0 commit comments

Comments
 (0)