Skip to content

Commit

Permalink
[Fix #1066] Fix an error for Rails/FilePath
Browse files Browse the repository at this point in the history
Fixes #1066.

This PR fixes an error for `Rails/FilePath`
when string interpolated `Rails.root` is followed by a message starting with `.`.
  • Loading branch information
koic committed Aug 14, 2023
1 parent 34376e0 commit db59655
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_rails_file_path.md
Original file line number Diff line number Diff line change
@@ -0,0 +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][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def extract_rails_root_join_argument_source(node, rails_root_index)
end

def extension_node?(node)
node&.str_type? && node.source.start_with?('.')
node&.str_type? && node.source.match?(/\A\.[A-Za-z]+/)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/file_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
end
end

context 'when string interpolated `Rails.root` is followed by a message starting with `.`' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root}. a message"
RUBY
end
end

context 'when using string interpolation without Rails.root' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
Expand Down

0 comments on commit db59655

Please sign in to comment.