Skip to content

Commit

Permalink
Fix Rails/FilePath cop error with rescued Rails.root
Browse files Browse the repository at this point in the history
  • Loading branch information
viralpraxis committed Dec 12, 2024
1 parent e470d18 commit 74892f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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 74892f1

Please sign in to comment.