Closed Jay-Schneider closed 2 years ago
I've opened #768, fixed autocorrection logic and marked the cop as unsafe due to the following incompatibility:
Dir.glob(Rails.root.join('foo/bar.rb'))
=> ["path/to/foo/bar.rb"]
Rails.root.glob('foo/bar.rb')
=> [#<Pathname:path/to/foo/bar.rb>]
Ah, true. It is not even the same 😅
I think marking the autocorrect unsafe is a fair solution. Thanks for addressing this so quickly.
Expected behavior
When rubocop detects a violation of of
Rails/RootPathnameMethods
and autocorrects it, I expect it to keep the behaviour of the code unchanged.Actual behavior
The code breaks, so autocorrection for this cop is not safe in the current version.
Steps to reproduce the problem
I was able to reproduce the problem with the following simple file:
When I run
rails runner foo.rb
it prints a list of files.rubocop foo.rb
reports the offenseNow, using
rubocop -a foo.rb
changes the content of the file towhich is not runnable code anymore and instead raises an error:
foo.rb:2:in 'glob': wrong number of arguments (given 0, expected 1..2) (ArgumentError)
I think what is supposed to happen when autocorrecting is
because this actually seems to be equivalent to the original code and does not violate the
Rails/RootPathnameMethods
cop. But that's not what's happening.RuboCop version