Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rails/FilePath cop error on join method with implicit receiver #1398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test and implementation like this seem to be required for both EnforcedStyle: 'arguments' and EnforcedStyle: 'slashes'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed.

end
end
Loading