Skip to content

Commit fecead8

Browse files
authored
Merge pull request #1399 from viralpraxis/fix-rails-file-path-cop-error-on-extra-operations-in-rails-root-interpolation
Fix `Rails/FilePath` cop error in case of extra operations in `Rails.root` interpolation
2 parents c6f869b + e4aee6b commit fecead8

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1398](https://github.com/rubocop/rubocop-rails/pull/1398): Fix `Rails/FilePath` cop error in case of extra operations in `Rails.root` interpolation. ([@viralpraxis][])

lib/rubocop/cop/rails/file_path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def check_for_slash_after_rails_root_in_dstr(node)
7676
rails_root_index = find_rails_root_index(node)
7777
slash_node = node.children[rails_root_index + 1]
7878
return unless slash_node&.str_type? && slash_node.source.start_with?(File::SEPARATOR)
79-
return if node.children[rails_root_index].each_descendant(:rescue).any?
79+
return unless node.children[rails_root_index].children.first.send_type?
8080

8181
register_offense(node, require_to_s: false) do |corrector|
8282
autocorrect_slash_after_rails_root_in_dstr(corrector, node, rails_root_index)

rubocop-rails-2.27.0.gem

110 KB
Binary file not shown.

spec/rubocop/cop/rails/file_path_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,14 @@
407407
end
408408
end
409409

410-
context 'when rescued concat Rails.root' do
411-
it 'does not register an offense' do
410+
context 'when interpolation with `Rails.root` contains other operations' do
411+
it 'does not register an offense for boolean method' do
412+
expect_no_offenses(<<~'RUBY')
413+
"#{Rails.root || '.'}/config"
414+
RUBY
415+
end
416+
417+
it 'does not register an offense for `rescue`' do
412418
expect_no_offenses(<<~'RUBY')
413419
"#{Rails.root rescue '.'}/config"
414420
RUBY

0 commit comments

Comments
 (0)