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

Fix a false positive and a true negative for Style/FetchEnvVar #10565

Merged
merged 1 commit into from Apr 23, 2022

Conversation

ydah
Copy link
Contributor

@ydah ydah commented Apr 22, 2022

This PR improves the edge case of Style/FetchEnvVar.
There are cases that are false positive and true negative, and it improves them.

false positive cases are as follows:

ENV['X'] &&= y

true negative cases are as follows:

y ||= ENV['X']
y &&= ENV['X']

This PR follows up on the same issue as the Issue raised at #10557.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@ydah ydah marked this pull request as ready for review Apr 22, 2022
lib/rubocop/cop/style/fetch_env_var.rb Outdated Show resolved Hide resolved
@deepj
Copy link
Contributor

deepj commented Apr 22, 2022

I have something like this in the code:

if Rails.env.production? && ENV['DISABLE_DOTENV'] != '1'

This is marked as (RuboCop 1.28.1)

C: [Correctable] Style/FetchEnvVar: Use ENV.fetch('DISABLE_DOTENV') or ENV.fetch('DISABLE_DOTENV', nil) instead of ENV['DISABLE_DOTENV'].
if Rails.env.production? && ENV['DISABLE_DOTENV'] != '1'

I guess this is missing in this PR to be fixed, right?

@ydah
Copy link
Contributor Author

ydah commented Apr 22, 2022

@deepj I think it looks a little different case than what this PR is trying to cover. Sorry.
From what I have seen of that code, it looks like Style/FetchEnvVar is what you want to detect.
Is it possible for you to write the details in Issue?

@ydah
Copy link
Contributor Author

ydah commented Apr 22, 2022

@koic Thank you for your review. I updated this PR.

@ydah ydah requested a review from koic Apr 22, 2022
@ydah
Copy link
Contributor Author

ydah commented Apr 23, 2022

I updated this PR. Thank you so much!

@ydah ydah requested a review from koic Apr 23, 2022
lib/rubocop/cop/style/fetch_env_var.rb Outdated Show resolved Hide resolved
@ydah ydah force-pushed the fix_fetch_env_var branch 2 times, most recently from d333d60 to 0194f25 Compare Apr 23, 2022
This PR improves the edge case of `Style/FetchEnvVar`.
There are cases that are false positive
and true negative, and it eliminates them.

false positive cases are as follows:
```ruby
ENV['X'] &&= y
```

true negative cases are as follows:
```ruby
y ||= ENV['X']
y &&= ENV['X']
```

This PR follows up on the same issue
as the Issue raised at rubocop#10557.
@ydah
Copy link
Contributor Author

ydah commented Apr 23, 2022

@koic Sorry for taking up your valuable time.
I updated this PR. Thank you so much.

@koic
Copy link
Member

koic commented Apr 23, 2022

Never mind! Thank you, too!

@koic koic merged commit 7606e2c into rubocop:master Apr 23, 2022
34 checks passed
@ydah ydah deleted the fix_fetch_env_var branch Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants