Skip to content
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

[Fix #7899] Fix an infinite loop error for Layout/SpaceAroundOperators #7901

Conversation

koic
Copy link
Member

@koic koic commented Apr 22, 2020

Fixes #7899.

This PR fixes the following infinite loop error for Layout/SpaceAroundOperators with Layout/ExtraSpacing when using ForceEqualSignAlignment: true.

% bundle exec rubocop -V
0.82.0 (using Parser 2.7.1.1, running on ruby 2.7.0 x86_64-darwin17)

% cat .rubocop.yml
Layout/ExtraSpacing:
  ForceEqualSignAlignment: true

% cat example.rb
test123456                = nil
test1234                   = nil
test1_test2_test3_test4_12 =nil

% bundle exec rubocop -a --only Layout/ExtraSpacing,Layout/SpaceAroundOperators
(snip)

Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/7899/example.rb.
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:287:in `check_for_infinite_loop'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:270:in `block in iterate_until_no_changes'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:269:in `loop'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the fix_an_infinite_loop_error_for_space_around_operators branch from ee4389b to f1ca186 Compare April 22, 2020 12:46
Copy link
Collaborator

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

@@ -170,6 +170,19 @@ def offense(type, operator, with_space, right_operand)
yield msg if msg
end

def enclose_operator_in_space(corrector, range)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's enclose_with, not enclose_in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this method name. Thank you!

…Operators`

Fixes rubocop#7899.

This PR fixes the following infinite loop error for `Layout/SpaceAroundOperators`
with `Layout/ExtraSpacing` when using `ForceEqualSignAlignment: true`.

```console
% bundle exec rubocop -V
0.82.0 (using Parser 2.7.1.1, running on ruby 2.7.0 x86_64-darwin17)

% cat .rubocop.yml
Layout/ExtraSpacing:
  ForceEqualSignAlignment: true

% cat example.rb
test123456                = nil
test1234                   = nil
test1_test2_test3_test4_12 =nil

% bundle exec rubocop -a --only Layout/ExtraSpacing,Layout/SpaceAroundOperators
(snip)

Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/7899/example.rb.
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:287:in
`check_for_infinite_loop'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:270:in
`block in iterate_until_no_changes'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:269:in
`loop'
/Users/koic/src/github.com/rubocop-hq/rubocop/lib/rubocop/runner.rb:269:in
`iterate_until_no_changes'
```
@koic koic force-pushed the fix_an_infinite_loop_error_for_space_around_operators branch from f1ca186 to 8329663 Compare April 24, 2020 05:29
@koic koic merged commit db23f5e into rubocop:master Apr 24, 2020
@koic koic deleted the fix_an_infinite_loop_error_for_space_around_operators branch April 24, 2020 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinite loop detected (rubocop failed with code=2)
2 participants