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
autocorrect not very readable in boolean-or chains
#10788
Comments
@j-miyake Do you have any comments on this? |
Indeed. The autocorrect of this cop may decrease readability like the case reported by this issue. Initially, I took this as a trade-off, but considering some improvements or comments (like #10652, #10585 (comment)) made until today, |
The code would be like this if we relax the cop. |
… 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`.
The
Style/FetchEnvVar
cop is autocorrecting to code that doesn't seem like a style improvement when given code that accepts a few possible ENV variable names or has a chain of alternatives. Note that since ENV values are strings,||
does not risk discarding a0
in the environment as it's a truthy"0"
right now.This satisfies the cop and might be a better autocorrect when there's more than a single alternative, but it's still a bit odd:
and short sets of options seem like too little to switch to an array-oriented way of doing this:
I'd ask someone to prefer simplicity over cleverness if I saw the above.
One could definitely get out of hand with with a boolean chain but I'm sure they'd cross other cops in doing so, while the longest examples I'm dealing with here are 3 terms. Four is the point where I'd personally switch to a different style or refactor.
I think this cop could be relaxed when it finds
ENV[...] || ...
on the LHS of another|| ...
?RuboCop version
The text was updated successfully, but these errors were encountered: