Skip to content

Commit

Permalink
Merge pull request #251 from eugeneius/file_path_final_interpolation
Browse files Browse the repository at this point in the history
Ignore Rails.root interpolation at end of string
  • Loading branch information
koic authored May 26, 2020
2 parents b37fc42 + 106249b commit b018933
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#12](https://github.com/rubocop-hq/rubocop-rails/issues/12): Fix a false positive for `Rails/SkipsModelValidations` when passing a boolean literal to `touch`. ([@eugeneius][])
* [#238](https://github.com/rubocop-hq/rubocop-rails/issues/238): Fix auto correction for `Rails/IndexBy` when the `.to_h` invocation is separated in multiple lines. ([@diogoosorio][])
* [#248](https://github.com/rubocop-hq/rubocop-rails/pull/248): Fix a false positive for `Rails/SaveBang` when `update` is called on `ENV`. ([@eugeneius][])
* [#251](https://github.com/rubocop-hq/rubocop-rails/pull/251): Fix a false positive for `Rails/FilePath` when the result of `Rails.root.join` is interpolated at the end of a string. ([@eugeneius][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rails/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FilePath < Cop

def on_dstr(node)
return unless rails_root_nodes?(node)
return unless node.children.last.str_type?
return unless node.children.last.source.start_with?('.') ||
node.children.last.source.include?(File::SEPARATOR)

Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/rails/file_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
end
end

context 'when using Rails.root.join in string interpolation with nothing after it' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root.join('log/production.log')}"
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 Expand Up @@ -135,6 +143,14 @@
end
end

context 'when using Rails.root.join in string interpolation with nothing after it' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root.join('log', 'production.log')}"
RUBY
end
end

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

0 comments on commit b018933

Please sign in to comment.