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

Style/FetchEnvVar - false positive cases with (not) equal operators #10581

Closed
deepj opened this issue Apr 25, 2022 · 0 comments · Fixed by #10582
Closed

Style/FetchEnvVar - false positive cases with (not) equal operators #10581

deepj opened this issue Apr 25, 2022 · 0 comments · Fixed by #10582
Labels

Comments

@deepj
Copy link
Contributor

deepj commented Apr 25, 2022

Expected behavior

No issue while using ENVs and (not) equal operators

if ENV['DISABLE_DOTENV'] != '1'
  # Some Ruby code
end

Actual behavior

Style/FetchEnvVar: Use ENV.fetch('DISABLE_DOTENV') or ENV.fetch('DISABLE_DOTENV', nil) instead of ENV['DISABLE_DOTENV'].
if ENV['DISABLE_DOTENV'] != '1'
   ^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

Code snippet

if ENV['DISABLE_DOTENV'] != '1'
  # Some Ruby code
end

Run

rubocop --only Style/FetchEnvVar

RuboCop version

$ rubocop -V
1.28.2 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.1.2 arm64-darwin21)
  - rubocop-performance 1.13.3
  - rubocop-rails 2.14.2
@deepj deepj changed the title Style/FetchEnvVar - a false positive cases with (not) equal operators Style/FetchEnvVar - false positive cases with (not) equal operators Apr 25, 2022
@koic koic added the bug label Apr 26, 2022
koic added a commit to koic/rubocop that referenced this issue Apr 26, 2022
Fixes rubocop#10581.

This PR fixes a false positive for `Style/FetchEnvVar` when comparing with `ENV['TERM']`.
`ENV['DISABLE_DOTENV'] != '1'` could be treated the same as the already allowed in `used_as_flag?`
(that is, used as a flag).
koic added a commit that referenced this issue Apr 29, 2022
…tch_env_var_cop

[Fix #10581] Fix a false positive for `Style/FetchEnvVar`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants