Skip to content
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

Add Rails/FilePath auto-correct #434

Closed
grosser opened this issue Feb 6, 2021 · 6 comments
Closed

Add Rails/FilePath auto-correct #434

grosser opened this issue Feb 6, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@grosser
Copy link
Contributor

grosser commented Feb 6, 2021

test/integration/cleanliness_test.rb:9:46: C: Rails/FilePath: Please use Rails.root.join('path/to') instead.
    files -= [File.expand_path(__FILE__).sub("#{Rails.root}/", '')]
                                             ^^^^^^^^^^^^^^^^

Expected behavior

autocorrect

Actual behavior

no autocorrect

Steps to reproduce the problem

see code above

RuboCop version

1.9.1 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.6.5 x86_64-darwin19)
  - rubocop-rails 2.9.1
@koic
Copy link
Member

koic commented Feb 8, 2021

C is an abbreviation for Convension, not an abbreviation for Correctable. So, C does not mention auto-correction. Also, W is an abbreviation for Warning. So, I think this is the expected behavior.
https://docs.rubocop.org/rubocop/1.9/formatters.html#progress-formatter-default

Currently RuboCop Rails (2.9) doesn't support auto-correct for Rails/FilePath.
https://docs.rubocop.org/rubocop-rails/2.9/cops_rails.html#railsfilepath

OTOH, I think it can be safely auto-corrected (rubocop -a), so it should be possible to enhance Rails/FilePath.

@koic koic added the enhancement New feature or request label Feb 8, 2021
@grosser grosser changed the title Rails/FilePath says it's correctable but fails to correct when using -A Add Rails/FilePath auto-correct Feb 8, 2021
@grosser
Copy link
Contributor Author

grosser commented Feb 8, 2021

ah thx, I always thought it's correction because they usually had an auto-correct 👍

@grosser
Copy link
Contributor Author

grosser commented Feb 8, 2021

I updated the title/descriotion

@henrahmagix
Copy link

Autocorrection for this appears to have been added in #991

The exact example given here now autocorrects from:

File.expand_path(__FILE__).sub("#{Rails.root}/", '')

to

File.expand_path(__FILE__).sub("#{Rails.root.join('')}", '')

@henrahmagix
Copy link

@grosser sorry I forgot to say that the autocorrect actually breaks the original intention of the code (it's getting rid of the trailing slash, meaning that slash doesn't get deleted by the .sub call), so it's a bug: see #1177 =)

@grosser
Copy link
Contributor Author

grosser commented Nov 2, 2023

ah thx, I was like "looks sus but at least it will shut up" :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants