Skip to content

Commit 2671fb4

Browse files
authored
Merge pull request #1398 from viralpraxis/fix-rails-file-path-cop-error-on-join-method-implicit-receiver
Fix `Rails/FilePath` cop error on `join` method with implicit receiver
2 parents fecead8 + 815d119 commit 2671fb4

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1397](https://github.com/rubocop/rubocop-rails/pull/1397): Fix `Rails/FilePath` cop error on `join` method with implicit receiver. ([@viralpraxis][])

lib/rubocop/cop/rails/file_path.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def on_dstr(node)
6666

6767
def on_send(node)
6868
check_for_file_join_with_rails_root(node)
69+
return unless node.receiver
70+
6971
check_for_rails_root_join_with_slash_separated_path(node)
7072
check_for_rails_root_join_with_string_arguments(node)
7173
end

spec/rubocop/cop/rails/file_path_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@
236236
RUBY
237237
end
238238
end
239+
240+
context 'with `join` method with implicit receiver' do
241+
it 'does not register an offense' do
242+
expect_no_offenses(<<~RUBY)
243+
join(Rails.root, path)
244+
RUBY
245+
end
246+
end
239247
end
240248

241249
context 'when EnforcedStyle is `arguments`' do
@@ -420,5 +428,13 @@
420428
RUBY
421429
end
422430
end
431+
432+
context 'with `join` method with implicit receiver' do
433+
it 'does not register an offense' do
434+
expect_no_offenses(<<~RUBY)
435+
join(Rails.root, path)
436+
RUBY
437+
end
438+
end
423439
end
424440
end

0 commit comments

Comments
 (0)