-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
0.41.1: Style/EachForSimpleLoop autocorrection calculates wrong number of repetitions #3271
Comments
This was not completely fixed by #3221, the code https://github.com/bbatsov/rubocop/blob/e2af464b809180ae2de1785c362c25291995e586/lib/rubocop/cop/style/each_for_simple_loop.rb#L38 finds |
This is pretty bad actually. All the unit tests are incorrect. Example:
But |
… cop There is a bug in `Style/EachForSimpleLoop`, where it auto-corrects with the wrong number of iterations. Consider: ``` (0..10).each { ... } ``` This is an inclusive range of 0 through 10, i.e. 11 iterations. This incorrectly gets auto-corrected to: ``` 10.times { ... } ``` It turns out the tests for this auto-correct are incorrect, and missing test cases for the exclusive range cases. This fix adds test coverage, and makes the auto-correct behave well for inclusive ranges.
… cop (rubocop#3297) There is a bug in `Style/EachForSimpleLoop`, where it auto-corrects with the wrong number of iterations. Consider: ``` (0..10).each { ... } ``` This is an inclusive range of 0 through 10, i.e. 11 iterations. This incorrectly gets auto-corrected to: ``` 10.times { ... } ``` It turns out the tests for this auto-correct are incorrect, and missing test cases for the exclusive range cases. This fix adds test coverage, and makes the auto-correct behave well for inclusive ranges.
Style/EachForSimpleLoop autocorrection calculates wrong number of repetitions.
Test case
Expected behavior
Actual behavior
Steps to reproduce the problem
test.rb
filerubocop -a
RuboCop version
The text was updated successfully, but these errors were encountered: