Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore Rails.root interpolation at end of string #251

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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