-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Performance/Sum not autocorrecting injects or reduces with blocks #171
Comments
|
- Fixes #208 - The rule isn't [working as intentended](rubocop/rubocop-performance#171)
This is an expected behavior, example - https://github.com/rubocop-hq/rubocop-performance/blob/368b748d1c6df62002f2a1b58e4258100e693841/spec/rubocop/cop/performance/sum_spec.rb#L73-L80 We cannot autocorrect when initial value is not given, because we do not know array item types. |
Or we can autocorrect, but mark this cop as unsafe. |
Fixes rubocop#171. This PR makes `Performance/Sum` cop can be changed auto-correction scope depending on the value of `SafeAutoCorrect` in .rubocop.yml. Its auto-correction is marked as safe by default (`SafeAutoCorrect: true`) to prevent `TypeError` in auto-correced code when initial value is not specified as shown below: ```ruby ['a', 'b'].sum # => (String can't be coerced into Integer) ``` Therefore if initial value is not specify as in that code, it will not be auto-corrected. If user always want to enable auto-correction, user can set `SafeAutoCorrect: false`. ```yaml Performance/Sum: SafeAutoCorrect: false ``` `SafeAutoCorrect` remains `true` by default, so the behavior does not change.
Somehow I was not notified on these updates. Thank you for the clarification. |
Fixes rubocop#171. This PR makes `Performance/Sum` cop can be changed auto-correction scope depending on the value of `SafeAutoCorrect` in .rubocop.yml. Its auto-correction is marked as safe by default (`SafeAutoCorrect: true`) to prevent `TypeError` in auto-correced code when initial value is not specified as shown below: ```ruby ['a', 'b'].sum # => (String can't be coerced into Integer) ``` Therefore if initial value is not specify as in that code, it will not be auto-corrected. If user always want to enable auto-correction, user can set `SafeAutoCorrect: false`. ```yaml Performance/Sum: SafeAutoCorrect: false ``` `SafeAutoCorrect` remains `true` by default, so the behavior does not change.
…ormance_sum [Fix #171] Extend auto-correction support for `Performance/Sum`
Expected behavior
After enabling
Performance/Sum
, I expect that the following lines will all be autocorrected to usesum
:Actual behavior
It only autocorrects the second line:
Steps to reproduce the problem
rubocop -A
OR
You can replicate this bug by pulling down this project, doing a
bundle install
, and runningrubocop -A
RuboCop version
The text was updated successfully, but these errors were encountered: