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
Cop idea: Replace ENV['HOME']
with Dir.home
#10568
Labels
Comments
ShockwaveNN
changed the title
Cop idea: Replace
Cop idea: Replace Apr 22, 2022
ENV['HOME'] with
Dir.home`ENV['HOME']
with Dir.home
I believe Dir.home may be the better alternative these days. I don't recall since when it was available, but I remember in the very old days we primarily used ENV['HOME']. Dir.home is probably a tiny bit easier to type too - not that it makes a huge difference. But I think if we have not forgotten about some use case then this proposal is probably useful. That is of course only my personal opinion. |
koic
added a commit
to koic/rubocop
that referenced
this issue
May 3, 2022
Fixes rubocop#10568. This cop checks for consistent usage of `ENV['HOME']`. If `nil` is used as the second argument of `ENV.fetch`, it is treated as a bad case like `ENV[]`. This avoids conflicts with `Style/FetchEnvVar`'s autocorrection. ## Safety The cop is unsafe because The result when `nil` is assigned to `ENV['HOME']` changes: ```ruby ENV['HOME'] = nil ENV['HOME'] # => nil Dir.home # => '/home/foo' ``` ## Example ```ruby # bad ENV['HOME'] ENV.fetch('HOME', nil) # good Dir.home # good ENV.fetch('HOME', default) ```
bbatsov
pushed a commit
that referenced
this issue
May 6, 2022
Fixes #10568. This cop checks for consistent usage of `ENV['HOME']`. If `nil` is used as the second argument of `ENV.fetch`, it is treated as a bad case like `ENV[]`. This avoids conflicts with `Style/FetchEnvVar`'s autocorrection. ## Safety The cop is unsafe because The result when `nil` is assigned to `ENV['HOME']` changes: ```ruby ENV['HOME'] = nil ENV['HOME'] # => nil Dir.home # => '/home/foo' ``` ## Example ```ruby # bad ENV['HOME'] ENV.fetch('HOME', nil) # good Dir.home # good ENV.fetch('HOME', default) ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
While fixing issues from latest rubocop update with
Style/FetchEnvVar
cop I found a lot of placed in my code where construction like this used:I got two problems:
Style/FetchEnvVar
advice to useWindows
system (but cannot check it)Describe the solution you'd like
Cop that replace all
ENV['HOME']
toDir.home
wich will be pure ruby solution to get home dirBut maybe there is some downside in this, but I'm not aware of such
The text was updated successfully, but these errors were encountered: