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
Prefer using slashes in Rails/FilePath cop #195
Comments
Good find. FWIW, we disable this cop at our shop and use the |
At the very least the style should be configurable. |
When trying to integrate this change we discovered that there is a difference in how absolute paths are resolved with each approach. For example:
We decided to stick with the separate arguments for the sake of consistency. |
Rubocop doesn't like it when I use the form: ``Rails.root.join('some', 'path', 'here')``` and wants me to use the more OS dependent ```Rails.root.join('some/path/here')```. See rubocop/rubocop-rails#195 (comment)
Rubocop doesn't like it when I use the form: ``Rails.root.join('some', 'path', 'here')``` and wants me to use the more OS dependent ```Rails.root.join('some/path/here')```. See rubocop/rubocop-rails#195 (comment)
When building paths, instead of using String interpolation Although beware that in your example you are joining a path that starts with path = File.expand_path('./app/models/user.rb')
# => "/Users/juancervantes/Desktop/synchroform/app/models/user.rb"
Rails.root.join('app', 'models', path)
# => #<Pathname:/Users/juancervantes/Desktop/synchroform/app/models/user.rb>
Rails.root.join('app/models', path)
# => #<Pathname:/Users/juancervantes/Desktop/synchroform/app/models/user.rb>
Rails.root.join('whatever', 'since', 'this', 'is', 'ignored', path)
# => #<Pathname:/Users/juancervantes/Desktop/synchroform/app/models/user.rb>
Pathname.new(path)
# => #<Pathname:/Users/juancervantes/Desktop/synchroform/app/models/user.rb> So do not concatenate expanded paths, simply do: path = "app/models/user.rb"
Rails.root.join('app/models', path) |
I feel like this should be revisited in light of @sunny's comment. It sounds like what this cop should be doing is guarding against string interpolation. |
Under Windows,
Rails.root.join('app', 'models', 'goober')
is equal toRails.root.join('app/models/goober')
. They both return a string with forward slashes.I'm in favor of always using the simple slashes and deprecating the previous join. The current cop suggests this is
but there is no evidence of such bugs.
More discussion of the issue here: https://twitter.com/tenderlove/status/842064491936280576
Expected behavior
Rails/FilePath should treat as:
Actual behavior
Today it treats the following as:
The text was updated successfully, but these errors were encountered: