You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If value isn't defined, the original code will set it to 'default' while the autocorrected code will set it to nil.
I usually try to avoid using defined? altogether. But the example above is similar to what I was seeing in some legacy code and I wanted to document it.
Often code like this can be rewritten to use ||=, as long a false value doesn't ever need to override the default. Or it could be rewritten to use an additional value_defined variable that is set before the assignment of value.
I'm not sure what an autocorrection could be for this situation. Maybe RuboCop shouldn't do anything here?
Say that I have code like:
This is reported as a
Style/IfUnlessModifier
failure. If I autocorrect it, it changes to:If
value
isn't defined, the original code will set it to'default'
while the autocorrected code will set it tonil
.I usually try to avoid using
defined?
altogether. But the example above is similar to what I was seeing in some legacy code and I wanted to document it.Often code like this can be rewritten to use
||=
, as long afalse
value doesn't ever need to override the default. Or it could be rewritten to use an additionalvalue_defined
variable that is set before the assignment ofvalue
.I'm not sure what an autocorrection could be for this situation. Maybe RuboCop shouldn't do anything here?
RuboCop version
The text was updated successfully, but these errors were encountered: