-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
FilePath safe autocorrect breaks code #1071
Labels
bug
Something isn't working
Comments
9 tasks
corsonknowles
added a commit
to corsonknowles/rubocop-rails
that referenced
this issue
Dec 23, 2024
…filepaths by marking cop as unsafe for autocorrection We correctly add a @safety annotation for Rails/FilePath since it can produce invalid code like this: # pass any string argument beginning with '/' to Rails.root.join and it will omit the Rails path (dev)> Rails.root.join '/' => #<Pathname:/> (dev)> Rails.root.join '//' => #<Pathname://> (dev)> Rails.root.join '/abc' => #<Pathname:/abc> (dev)> Rails.root.join '/abc/' => #<Pathname:/abc/>
Safe autocorrect should never break code, so I have opened a PR here to mark this cop as unsafe for this reason: |
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Jan 27, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Jan 30, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 2, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 2, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 2, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 2, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 2, 2025
…hen File.join is used with a variable
corsonknowles
added a commit
to corsonknowles/rubocop-rails
that referenced
this issue
Feb 3, 2025
…filepaths by marking cop as unsafe for autocorrection We correctly add a @safety annotation for Rails/FilePath since it can produce invalid code like this: # pass any string argument beginning with '/' to Rails.root.join and it will omit the Rails path (dev)> Rails.root.join '/' => #<Pathname:/> (dev)> Rails.root.join '//' => #<Pathname://> (dev)> Rails.root.join '/abc' => #<Pathname:/abc> (dev)> Rails.root.join '/abc/' => #<Pathname:/abc/>
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 4, 2025
…hen File.join is used with a variable
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 5, 2025
….join` with variables and ignore leading and multiple slashes in string literal arguments for `Rails.root.join` and `File.join`
ydakuka
added a commit
to ydakuka/rubocop-rails
that referenced
this issue
Feb 6, 2025
….join` with variables and ignore leading and multiple slashes in string literal arguments for `Rails.root.join` and `File.join`
koic
added a commit
that referenced
this issue
Feb 7, 2025
…the-rails-file-path-cop-when-file-join-is-used-with-a-variable [Fix #1071] Fix `Rails/FilePath` cop to correctly handle `File.join` with variables and ignore leading and multiple slashes in string literal arguments for `Rails.root.join` and `File.join`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The cop Rails/FilePath replaces
File.join
withPathname.join
but they are not equivalent when the argument has a leading slash. A similar issue has been reported before:The replacement breaks code with path parts starting with a slash:
Expected behavior
Rails/FilePath should be marked as unsafe. And the message could be updated:
Actual behavior
Message:
Note that a shortened version is not flagged by this cop:
However, it's flagged by Rails/RootPathnameMethods which is correctly marked as unsafe.
Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: