Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1001](https://github.com/rubocop/rubocop-rails/pull/1001): Exclude `File.join` from `Rails/RootPathnameMethods` target methods. ([@r7kamura][])
1 change: 0 additions & 1 deletion lib/rubocop/cop/rails/root_pathname_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class RootPathnameMethods < Base
fnmatch?
ftype
grpowned?
join
lchmod
lchown
lstat
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/root_pathname_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,10 @@
file = Rails.root.join('docs', 'invoice.pdf').open
RUBY
end

it 'does not register an offense when using `File.join(Rails.root, ...)`' do
expect_no_offenses(<<~RUBY)
File.join(Rails.root, '/foo')
Copy link
Member

Choose a reason for hiding this comment

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

The detection should occur unless the 2nd argument+ of File.join starts with a /.

Pathname.new('/foo').join('/bar').to_s # unexpected "/bar"
Pathname.new('/foo').join('bar').to_s  # expected "/foo/bar"

See for details: https://bugs.ruby-lang.org/issues/19155

RUBY
end
end