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
Style/FetchEnvVar
check for if
condition
#10569
Comments
But in same time there may be code like this: if ENV['foo']
ENV.delete('foo')
puts 'some code'
puts ENV['foo']
puts 'other code'
end And fetch is required in this code, so I'm thinking that correct check via |
EDIT: Misread the issue. |
Fixes rubocop#10569. This PR fixes a false positive for `Style/FetchEnvVar` when using the same value of `ENV` as `if` condition in the body. The `ENV` var as a `if` condition is currently allowed. So the `ENV` var already used in the condition will be accepted as well. And the following (maybe) corner case is accepted in this PR. ```ruby if ENV['foo'] ENV.delete('foo') puts 'some code' puts ENV['foo'] puts 'other code' end ``` rubocop#10569 (comment)
Fixes #10569. This PR fixes a false positive for `Style/FetchEnvVar` when using the same value of `ENV` as `if` condition in the body. The `ENV` var as a `if` condition is currently allowed. So the `ENV` var already used in the condition will be accepted as well. And the following (maybe) corner case is accepted in this PR. ```ruby if ENV['foo'] ENV.delete('foo') puts 'some code' puts ENV['foo'] puts 'other code' end ``` #10569 (comment)
Not sure that
rubocop
can check it or dynamic check is required for such checks, but I'll report it anywaySteps to reproduce the problem
test.rb
with content:rubocop -A
checkresult code will be:
So fetch is literally useless in code like this
RuboCop version
The text was updated successfully, but these errors were encountered: