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

Infinite loop detected (rubocop failed with code=2) #7899

Closed
hackhowtofaq opened this issue Apr 21, 2020 · 3 comments · Fixed by #7901
Closed

Infinite loop detected (rubocop failed with code=2) #7899

hackhowtofaq opened this issue Apr 21, 2020 · 3 comments · Fixed by #7901
Labels

Comments

@hackhowtofaq
Copy link

hackhowtofaq commented Apr 21, 2020

I have the following code

test123456                = nil 
test1234                   = nil
test12345678910            = nil
test1_test2_test3_test4_12 = nil

Expected behavior

Align =

test123456                 = nil 
test1234                   = nil
test12345678910            = nil
test1_test2_test3_test4_12 = nil

Describe here how you expected RuboCop to behave in this particular situation.

Actual behavior

# > rubocop rubocop_error.rb -a
# Inspecting 1 file
# C
#
# Offenses:
#
# rubocop_error.rb:1:27: C: [Corrected] Layout/SpaceAroundOperators: Operator = should be surrounded by a single space.
# test123456                = nil 
#                           ^
# rubocop_error.rb:1:28: C: [Corrected] Layout/SpaceAroundOperators: Operator = should be surrounded by a single space.
# test123456                 = nil
#                            ^
# rubocop_error.rb:2:10: C: [Corrected] Layout/ExtraSpacing: = is not aligned with the preceding assignment.
# test1234 = nil
#          ^
# rubocop_error.rb:2:28: C: [Corrected] Layout/ExtraSpacing: = is not aligned with the preceding assignment.
# test1234                   = nil
#                            ^
# rubocop_error.rb:2:28: C: [Corrected] Layout/SpaceAroundOperators: Operator = should be surrounded by a single space.
# test1234                   = nil
#                            ^
# rubocop_error.rb:3:17: C: [Corrected] Layout/ExtraSpacing: = is not aligned with the preceding assignment.
# test12345678910 = nil
#                 ^
# rubocop_error.rb:3:28: C: [Corrected] Layout/ExtraSpacing: = is not aligned with the preceding assignment.
# test12345678910            = nil
#                            ^
# rubocop_error.rb:3:28: C: [Corrected] Layout/SpaceAroundOperators: Operator = should be surrounded by a single space.
# test12345678910            = nil
#                            ^
# rubocop_error.rb:4:28: C: [Corrected] Layout/ExtraSpacing: = is not aligned with the preceding assignment.
# test1_test2_test3_test4_12 = nil
#                            ^
#
# 0 files inspected, 9 offenses detected, 9 offenses corrected
# Infinite loop detected in rubocop_error.rb.
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:287:in `check_for_infinite_loop'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:270:in `block in iterate_until_no_changes'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:269:in `loop'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:269:in `iterate_until_no_changes'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:240:in `do_inspection_loop'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:119:in `block in file_offenses'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:143:in `file_offense_cache'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:117:in `file_offenses'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:108:in `process_file'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:86:in `each'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:86:in `reduce'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:73:in `inspect_files'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/runner.rb:39:in `run'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli/command.rb:10:in `run'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli/environment.rb:17:in `run'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli.rb:65:in `run_command'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli.rb:72:in `execute_runners'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli.rb:41:in `run'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/exe/rubocop:13:in `block in <top (required)>'
# .rbenv/versions/2.6.5/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
# .rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/exe/rubocop:12:in `<top (required)>'
# .rbenv/versions/2.6.5/bin/rubocop:23:in `load'
# .rbenv/versions/2.6.5/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Save the first snippet as rubocop_error.rb and execute

> rubocop rubocop_error.rb -a

RuboCop version

$ [bundle exec] rubocop -V
0.82.0 (using Parser 2.7.1.1, running on ruby 2.6.5 x86_64-linux)
@koic
Copy link
Member

koic commented Apr 22, 2020

I cannot reproduce this issue in the default configuration of RuboCop. Con you show me your .rubocop.yml?

@hackhowtofaq
Copy link
Author

.rubocop.yml

inherit_from: .rubocop_todo.yml

require:
  - rubocop-performance
# Rails:
#   Enabled: true

.rubocop_todo.yml

# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-09-11 10:29:45 +0300 using RuboCop version 0.59.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Cop supports --auto-correct.
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
  Exclude:
    - "Gemfile"

Layout/HashAlignment:
  Enabled: true
  EnforcedColonStyle: table
  EnforcedLastArgumentHashStyle: always_inspect

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith.
# SupportedStylesAlignWith: either, start_of_block, start_of_line
Layout/BlockAlignment:
  Enabled: true

# Cop supports --auto-correct.
Layout/ClosingParenthesisIndentation:
  Enabled: true

Layout/CommentIndentation:
  Enabled: true

# Layout/DefEndAlignment:
#   Enabled: true
# AutoCorrect: true
# EnforcedStyleAlignWith: def

# Offense count: 1
# Cop supports --auto-correct.
Layout/ElseAlignment:
  Enabled: true

# Offense count: 26
# Cop supports --auto-correct.
Layout/EmptyLines:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
  Enabled: false

# Cop supports --auto-correct.
Layout/EmptyLinesAroundMethodBody:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Layout/EndAlignment:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Layout/ExtraSpacing:
  AllowForAlignment: true
  ForceEqualSignAlignment: true
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
Layout/FirstArgumentIndentation:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/FirstHashElementIndentation:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: normal, rails
Layout/IndentationConsistency:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Layout/IndentationWidth:
  Enabled: true

# Cop supports --auto-correct.
Layout/LeadingCommentSpace:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Layout/SpaceAroundOperators:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceInsideParens:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceInsideStringInterpolation:
  Enabled: false

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Layout/IndentationStyle:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
  Enabled: true

# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
  Enabled: true

# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
  Enabled: true

Lint/LiteralAsCondition:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
  Enabled: false

Lint/UselessAssignment:
  Enabled: true

Metrics/AbcSize:
  Max: 253

# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
  Max: 171

# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
  Max: 4

# Configuration parameters: CountComments.
Metrics/ClassLength:
  Max: 533

Metrics/CyclomaticComplexity:
  Max: 21

# Configuration parameters: CountComments.
Metrics/MethodLength:
  Max: 130

Metrics/PerceivedComplexity:
  Max: 23

# Configuration parameters: EnforcedStyle.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
  EnforcedStyle: camelCase
  Enabled: true

# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to, by, on, in, at, ip, db
Naming/MethodParameterName:
  Enabled: false

# Configuration parameters: .
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
  EnforcedStyle: snake_case
  Enabled: true

# Configuration parameters: EnforcedStyle.
# SupportedStyles: snake_case, normalcase, non_integer
Naming/VariableNumber:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
  Enabled: false

Style/Documentation:
  Enabled: true

# Offense count: 1
# Cop supports --auto-correct.
Style/EachWithObject:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: when_needed, always, never
Style/FrozenStringLiteralComment:
  Enabled: false

Style/GuardClause:
  Enabled: false

Style/IfInsideElse:
  Enabled: true

# Cop supports --auto-correct.
Style/IfUnlessModifier:
  Enabled: false

Style/IfWithSemicolon:
  Enabled: true

# Cop supports --auto-correct.
Style/InfiniteLoop:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: InverseMethods, InverseBlocks.
Style/InverseMethods:
  Enabled: true

Style/NegatedIf:
  Enabled: false

Style/NegatedWhile:
  Enabled: false

Style/Next:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: Strict.
Style/NumericLiterals:
  MinDigits: 14

Style/NumericPredicate:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: short, verbose
Style/PreferredHashMethods:
  Enabled: true

# Cop supports --auto-correct.
Style/RedundantConditional:
  Enabled: true

# Cop supports --auto-correct.
Style/RedundantParentheses:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
  Enabled: true

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
  Enabled: false

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
  Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantInterpolation:
  Enabled: true
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https

Lint/RaiseException:
  Enabled: false

Lint/StructNewOverride:
  Enabled: false

Style/HashEachMethods:
  Enabled: false

Style/HashTransformKeys:
  Enabled: false

Style/HashTransformValues:
  Enabled: false

Layout/LineLength:
  Max: 294

Layout/SpaceAroundMethodCallOperator:
  Enabled: false

Style/ExponentialNotation:
  Enabled: false

@koic
Copy link
Member

koic commented Apr 22, 2020

Thanks for the showing me your .rubocop.yml. I can reproduce this issue.

@koic koic added the bug label Apr 22, 2020
koic added a commit to koic/rubocop that referenced this issue Apr 24, 2020
…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 added a commit that referenced this issue Apr 24, 2020
…ce_around_operators

[Fix #7899] Fix an infinite loop error for `Layout/SpaceAroundOperators`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants