Skip to content

Commit

Permalink
Merge pull request #1392 from viralpraxis/fix-rails-file-path-cop-err…
Browse files Browse the repository at this point in the history
…or-with-rescued-rails-root

Fix `Rails/FilePath` cop error with rescued `Rails.root`
  • Loading branch information
koic authored Dec 13, 2024
2 parents 0bbd218 + bb03d6b commit c6f869b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1392](https://github.com/rubocop/rubocop-rails/pull/1392): Fix `Rails/FilePath` cop error with rescued `Rails.root`. ([@viralpraxis][])
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 @@ -76,6 +76,7 @@ def check_for_slash_after_rails_root_in_dstr(node)
rails_root_index = find_rails_root_index(node)
slash_node = node.children[rails_root_index + 1]
return unless slash_node&.str_type? && slash_node.source.start_with?(File::SEPARATOR)
return if node.children[rails_root_index].each_descendant(:rescue).any?

register_offense(node, require_to_s: false) do |corrector|
autocorrect_slash_after_rails_root_in_dstr(corrector, node, rails_root_index)
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 @@ -406,5 +406,13 @@
RUBY
end
end

context 'when rescued concat Rails.root' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root rescue '.'}/config"
RUBY
end
end
end
end

0 comments on commit c6f869b

Please sign in to comment.