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 #10788] Relax Style/FetchEnvVar to allow ENV[] in LHS of || #10819

Merged
merged 1 commit into from Jul 21, 2022

Conversation

j-miyake
Copy link
Contributor

@j-miyake j-miyake commented Jul 15, 2022

Fixes #10788

This PR relaxes Style/FetchEnvVar cop to allow ENV[] in LHS of ||.
ENV[] in LHS of || operator can be allowed by this cop because the || is put by the developer who knows the LHS may be nil.

Current behavior

ENV['x'] || y
ENV['y'] || ENV['y'] || z

# corrected into..

ENV.fetch('x'){y}
ENV.fetch('x'){ENV.fetch('y'){z}}

New behavior

ENV['x'] || y
ENV['y'] || ENV['y'] || z

# no offenses

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.

… of `||`

Fixes rubocop#10788

This PR relaxes `Style/FetchEnvVar` cop to allow `ENV[]` in LHS of `||`.
`ENV[]` in LHS of `||` operator can be allowed by this cop because
the `||` is put by the developer who knows the LHS may be `nil`.
@j-miyake j-miyake marked this pull request as ready for review July 19, 2022 23:59
@bbatsov bbatsov merged commit dd11b7b into rubocop:master Jul 21, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 21, 2022

Looks good. Thanks!

@j-miyake j-miyake deleted the relax_fetch_env_var_cop branch July 22, 2022 08:38
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.

Style/FetchEnvVar autocorrect not very readable in boolean-or chains
2 participants