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 with trailing private keyword in controller #6566

Closed
thisismydesign opened this issue Dec 10, 2018 · 1 comment · Fixed by #6576
Closed

Infinite loop detected with trailing private keyword in controller #6566

thisismydesign opened this issue Dec 10, 2018 · 1 comment · Fixed by #6576
Labels

Comments

@thisismydesign
Copy link

thisismydesign commented Dec 10, 2018

Expected behavior

No Infinite loop detected error as the controller otherwise works fine.

This was produced by a mistake as you can probably tell by the example below, I don't know if there's a cop already warning about trailing private keywords, maybe the expected behavior is to get an error there.

Actual behavior

Infinite loop detected error when my controller has a trailing private keyword.

rubocop -a

Infinite loop detected in /home/csaba/workspace/bla/app/controllers/some_controller.rb.
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:259:in `check_for_infinite_loop'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:242:in `block in iterate_until_no_changes'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:241:in `loop'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:241:in `iterate_until_no_changes'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:212:in `do_inspection_loop'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:115:in `block in file_offenses'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:133:in `file_offense_cache'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:113:in `file_offenses'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:101:in `process_file'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:75:in `each'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:75:in `reduce'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:75:in `each_inspected_file'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:67:in `inspect_files'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/runner.rb:39:in `run'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/cli.rb:157:in `execute_runner'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/cli.rb:85:in `execute_runners'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/lib/rubocop/cli.rb:41:in `run'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/exe/rubocop:13:in `block in <top (required)>'
/usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/home/csaba/.rvm/gems/ruby-2.5.1/gems/rubocop-0.60.0/exe/rubocop:12:in `<top (required)>'
/home/csaba/.rvm/gems/ruby-2.5.1/bin/rubocop:23:in `load'
/home/csaba/.rvm/gems/ruby-2.5.1/bin/rubocop:23:in `<main>'
/home/csaba/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'

Steps to reproduce the problem

My controller looks like this:

class SomeController < SomeOtherController
  def index
  end

  private
end

RuboCop version

0.60.0 (using Parser 2.5.3.0, running on ruby 2.5.1 x86_64-linux)

@koic
Copy link
Member

koic commented Dec 12, 2018

Thanks for the feedback. I opened a PR #6576.

koic added a commit to koic/rubocop that referenced this issue Dec 14, 2018
…ccessModifier`

Fixes rubocop#6566.

This PR fixes a false positive for `Layout/EmptyLinesAroundAccessModifier`
when at the end of specifying a superclass is missing blank line.

The following is originally no offense code.
(It is probably a regression by rubocop#6307)

```console
% cat example.rb
class SomeController < SomeOtherController
  def index; end

  private
end

% rubocop example.rb --only Layout/EmptyLinesAroundAccessModifier -a
Inspecting 1 file
C

Offenses:

example.rb:4:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
  private
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct adds a blank line after `private`. This is due to false positives.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
+
 end
```

This caused the infinite loop in `Layout/EmptyLinesAroundAccessModifier` and
`Layout/EmptyLinesAroundClassBody`.

```console
% rubocop example.rb --only Layout/EmptyLinesAroundClassBody -a
Inspecting 1 file
C

Offenses:

example.rb:5:1: C: [Corrected] Layout/EmptyLinesAroundClassBody: Extra
empty line detected at class body end.

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct removes the blank line from after of `private`.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
-
 end
```

It loops to the first code. This PR fixes the infinite loop.
bbatsov pushed a commit that referenced this issue Dec 14, 2018
…difier`

Fixes #6566.

This PR fixes a false positive for `Layout/EmptyLinesAroundAccessModifier`
when at the end of specifying a superclass is missing blank line.

The following is originally no offense code.
(It is probably a regression by #6307)

```console
% cat example.rb
class SomeController < SomeOtherController
  def index; end

  private
end

% rubocop example.rb --only Layout/EmptyLinesAroundAccessModifier -a
Inspecting 1 file
C

Offenses:

example.rb:4:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
  private
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct adds a blank line after `private`. This is due to false positives.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
+
 end
```

This caused the infinite loop in `Layout/EmptyLinesAroundAccessModifier` and
`Layout/EmptyLinesAroundClassBody`.

```console
% rubocop example.rb --only Layout/EmptyLinesAroundClassBody -a
Inspecting 1 file
C

Offenses:

example.rb:5:1: C: [Corrected] Layout/EmptyLinesAroundClassBody: Extra
empty line detected at class body end.

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct removes the blank line from after of `private`.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
-
 end
```

It loops to the first code. This PR fixes the infinite loop.
Nyangawa pushed a commit to Nyangawa/rubocop that referenced this issue Jan 24, 2019
…ccessModifier`

Fixes rubocop#6566.

This PR fixes a false positive for `Layout/EmptyLinesAroundAccessModifier`
when at the end of specifying a superclass is missing blank line.

The following is originally no offense code.
(It is probably a regression by rubocop#6307)

```console
% cat example.rb
class SomeController < SomeOtherController
  def index; end

  private
end

% rubocop example.rb --only Layout/EmptyLinesAroundAccessModifier -a
Inspecting 1 file
C

Offenses:

example.rb:4:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
  private
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct adds a blank line after `private`. This is due to false positives.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
+
 end
```

This caused the infinite loop in `Layout/EmptyLinesAroundAccessModifier` and
`Layout/EmptyLinesAroundClassBody`.

```console
% rubocop example.rb --only Layout/EmptyLinesAroundClassBody -a
Inspecting 1 file
C

Offenses:

example.rb:5:1: C: [Corrected] Layout/EmptyLinesAroundClassBody: Extra
empty line detected at class body end.

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct removes the blank line from after of `private`.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
-
 end
```

It loops to the first code. This PR fixes the infinite loop.
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.

3 participants