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
While upgrading our codebase to RuboCop 1.19.0 and running bundle exec rubocop -a, I noticed some failing specs. I believe the Style/RedundantSelfAssignmentBranch cop autocorrections should be marked unsafe. See the example below.
Expected behavior
bundle exec rubocop -a should not break existing code.
Actual behavior
bundle exec rubocop -a broke some existing code.
Steps to reproduce the problem
Let's say we have the following (rather odd) piece of code in test.rb:
classTestdeffoo@foo=if@foo_set@fooelse@foo_set=true@foo='bar'endendendtest=Test.newputstest.foo == 'bar'# should be trueputstest.foo == 'bar'# should be true
Running this file will give the following output:
true
true
RuboCop will display the following message on line 4:
Style/RedundantSelfAssignmentBranch: Remove the self-assignment branch.
Executing bundle exec rubocop -a test.rb will update the code to this:
classTestdeffoo@foo=unless@foo_set@foo_set=true@foo='bar'endendendtest=Test.newputstest.foo == 'bar'# should be trueputstest.foo == 'bar'# should be true
…gnmentBranch`
Fixesrubocop#10011.
This PR fixes a false positive for `Style/RedundantSelfAssignmentBranch`
when using instance variable, class variable, and global variable.
…ranch`
Fixes#10011.
This PR fixes a false positive for `Style/RedundantSelfAssignmentBranch`
when using instance variable, class variable, and global variable.
While upgrading our codebase to RuboCop 1.19.0 and running
bundle exec rubocop -a
, I noticed some failing specs. I believe the Style/RedundantSelfAssignmentBranch cop autocorrections should be marked unsafe. See the example below.Expected behavior
bundle exec rubocop -a
should not break existing code.Actual behavior
bundle exec rubocop -a
broke some existing code.Steps to reproduce the problem
Let's say we have the following (rather odd) piece of code in
test.rb
:Running this file will give the following output:
RuboCop will display the following message on line 4:
Executing
bundle exec rubocop -a test.rb
will update the code to this:Running this file will give a different output:
RuboCop version
The text was updated successfully, but these errors were encountered: