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
Style/RedundantBegin cop might auto-correct code incorrectly, leading to a performance issue or even a broken build. See example below:
Precondition
Given the following example class
classTestdefinitialize@first_run=falseenddefmemoized@memoized ||= begin'memoized'iffirst_runendenddeffirst_run# this might be an expensive operationfail'already run!'if@first_run@first_run=trueendend
and the following test code:
test=Test.new2.times{test.memoized}
Expected behavior
The code should not be auto-corrected, or maybe auto-corrected as the following:
classTestdefinitialize@first_run=falseenddefmemoized@memoized ||= ('memoized'iffirst_run)enddeffirst_run# this might be an expensive operationfail'already run!'if@first_run@first_run=trueendend
Actual behavior
The code is auto-corrected as follows:
classTestdefinitialize@first_run=falseenddefmemoized@memoized ||= 'memoized'iffirst_runenddeffirst_run# this might be an expensive operationfail'already run!'if@first_run@first_run=trueendend
…Begin`
Fixesrubocop#9681.
This PR fixes an incorrect auto-correct for `Style/RedundantBegin`
when using modifier `if` single statement in `begin` block.
Style/RedundantBegin cop might auto-correct code incorrectly, leading to a performance issue or even a broken build. See example below:
Precondition
Given the following example class
and the following test code:
Expected behavior
The code should not be auto-corrected, or maybe auto-corrected as the following:
Actual behavior
The code is auto-corrected as follows:
which makes the test code raise an exception.
RuboCop version
1.12.1 (using Parser 3.0.1.0, rubocop-ast 1.4.1, running on ruby 2.6.6 x86_64-linux)
The text was updated successfully, but these errors were encountered: