Skip to content

Commit

Permalink
Merge pull request #1398 from viralpraxis/fix-rails-file-path-cop-err…
Browse files Browse the repository at this point in the history
…or-on-join-method-implicit-receiver

Fix `Rails/FilePath` cop error on `join` method with implicit receiver
  • Loading branch information
koic authored Dec 23, 2024
2 parents fecead8 + 815d119 commit 2671fb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_merge_pull_request_1392_from.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1397](https://github.com/rubocop/rubocop-rails/pull/1397): Fix `Rails/FilePath` cop error on `join` method with implicit receiver. ([@viralpraxis][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def on_dstr(node)

def on_send(node)
check_for_file_join_with_rails_root(node)
return unless node.receiver

check_for_rails_root_join_with_slash_separated_path(node)
check_for_rails_root_join_with_string_arguments(node)
end
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 @@ -236,6 +236,14 @@
RUBY
end
end

context 'with `join` method with implicit receiver' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
join(Rails.root, path)
RUBY
end
end
end

context 'when EnforcedStyle is `arguments`' do
Expand Down Expand Up @@ -420,5 +428,13 @@
RUBY
end
end

context 'with `join` method with implicit receiver' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
join(Rails.root, path)
RUBY
end
end
end
end

0 comments on commit 2671fb4

Please sign in to comment.