-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
The suggestions of the FilePath cop cause a TypeError if %w is used to specify the path #1389
Comments
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Jan 18, 2025
…d RootPathname cops
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Jan 18, 2025
…d RootPathname cops
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Jan 18, 2025
…d RootPathname cops
This was referenced Jan 18, 2025
There is now ydakuka@yauhenid:~/Work/project$ rubocop test.rb
Inspecting 1 file
C
Offenses:
test.rb:3:1: C: [Correctable] Rails/FilePath: Prefer Rails.root.join('path/to').to_s.
File.join(Rails.root, %w[test files migration])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:3:1: C: [Correctable] Rails/RootPathnameMethods: Rails.root is a Pathname, so you can use Rails.root.join(%w[test files migration]).
File.join(Rails.root, %w[test files migration])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 2 offenses detected, 2 offenses autocorrectable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
With a line like
File.join(Rails.root, %w[test files migration])
with an array, it should be eitherA. be ignored or
B. turned into
Rails.root.join('test', 'files', 'migration').to_s
Personally, I prefer the notation with %w to minimize quotes. Thus I wouild choose option A, but I suspect gem author prefers B, which is acceptable.
Actual behavior
Running
Rails/FilePath
cop onFile.join(Rails.root, %w[test files migration])
turns intoRails.root.join(%w[test files migration]).to_s
, whichPathname.join
can't handle arraySteps to reproduce the problem
RuboCop version
Reference
Similar to #472 but specific when using %w
The text was updated successfully, but these errors were encountered: