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
Multiline conditional assignments are firing the Style/RedundantSelfAssignmentBranch rule. If this rule is applied, it modifies the conditional. In the falsey case, those conditionals evaluate to nil, and then nil is assigned (instead of no assignment).
Expected behavior
The Style/RedundantSelfAssignmentBranch does not fire for multiline if/else conditional assignments. Basically the cases covered by
The modification fails because the multiline conditional expression returns nil and that's what is assigned to the variable.
If the change recommended were instead (which perhaps is what Style/IfUnlessModifier does)
url = [url, path].join('/') if path
it would be correct, but as recommended / auto-corrected, it is not.
RuboCop version
Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:
…tSelfAssignmentBranch`
Fixesrubocop#10024.
This PR fixes an incorrect auto-correct for `Style/RedundantSelfAssignmentBranch`
when using multiline `if` / `else` conditional assignment.
…signmentBranch`
Fixes#10024.
This PR fixes an incorrect auto-correct for `Style/RedundantSelfAssignmentBranch`
when using multiline `if` / `else` conditional assignment.
Multiline conditional assignments are firing the
Style/RedundantSelfAssignmentBranch
rule. If this rule is applied, it modifies the conditional. In thefalsey
case, those conditionals evaluate tonil
, and thennil
is assigned (instead of no assignment).Expected behavior
The
Style/RedundantSelfAssignmentBranch
does not fire for multiline if/else conditional assignments. Basically the cases covered by07c8ef8#diff-9aa30a608c9b3f7d4c969285ada36ce789273d243e71262eeac97ae5a93ae1adR26-R34
Actual behavior
The rules do fire, leading to incorrect code
Steps to reproduce the problem
Using the configuration
to isolate the behavior to only this cop,
run the file
ruby join_if.rb
. Test passesRun
bundle exec rubocop -a
withStyle/RedundantSelfAssignmentBranch
enabled. Cop reportsThe modification fails because the multiline conditional expression returns
nil
and that's what is assigned to the variable.If the change recommended were instead (which perhaps is what
Style/IfUnlessModifier
does)it would be correct, but as recommended / auto-corrected, it is not.
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler.If you see extension cop versions (e.g.
rubocop-performance
,rubocop-rspec
, and others)output by
rubocop -V
, include them as well. Here's an example:The text was updated successfully, but these errors were encountered: