You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# this should be allowed by Rails/FilePath cop because the last / in /Users/me/rails_app/ must be deleted, not just /Users/me/rails_appmy_abs_path.delete_prefix("#{Rails.root}/")
Actual behavior
my_abs_path.delete_prefix("#{Rails.root}/")# raises Rails/FilePath, and is autocorrected tomy_abs_path.delete_prefix("#{Rails.root.join('')}")# which raises Style/RedundantInterpolation, so we manually correct tomy_abs_path.delete_prefix(Rails.root.join('').to_s)# which is wrong:actual=my_abs_path.delete_prefix(Rails.root.join('').to_s)actual == expected_relative_result# => falseputsactual# => "/config/locales/text_en.yml"# so we try giving an argument to join, but still wrong because Rails.root.join never adds a trailing slash:actual=my_abs_path.delete_prefix(Rails.root.join('./').to_s)actual == expected_relative_result# => falseputsactual# => "/config/locales/text_en.yml"
Steps to reproduce the problem
Copy the below into a file, run RuboCop with autocorrect enabled and manually fix any other cops that are raised, then assert that the result is true. rubocop-rails-filepath-test.rb
# where Rails.root is /Users/me/rails_appmy_abs_path="/Users/me/rails_app/config/locales/text_en.yml"expected_relative_result="config/locales/text_en.yml"actual=my_abs_path.delete_prefix("#{Rails.root}/")ifactual != expected_relative_resultraise"Invalid autocorrection: #{actual.inspect} != #{expected_relative_result.inspect}"end
rubocop -a rubocop-rails-filepath-test.rb
rubocop -A rubocop-rails-filepath-test.rb # autofix Style/RedundantInterpolation
bin/rails c < rubocop-rails-filepath-test.rb
I can see autocorrection was added in #991 so is this considered a bug of that? If so, then I can submit a fix that allows "#{Rails.root}/" if that's acceptable?
I also saw #1071 which might get fixed at the same time; I can check.
Also theres #434 which includes the exact same case as this.
I'm trying to use Rails.root to remove it from an absolute filepath to result in a filepath relative to Rails.root.
Expected behavior
Actual behavior
Steps to reproduce the problem
Copy the below into a file, run RuboCop with autocorrect enabled and manually fix any other cops that are raised, then assert that the result is true.
rubocop-rails-filepath-test.rb
RuboCop version
The text was updated successfully, but these errors were encountered: