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

rubocop replaces "end" with "nd" in certain situations #8232

Closed
stillhart opened this issue Jul 3, 2020 · 1 comment · Fixed by #8233
Closed

rubocop replaces "end" with "nd" in certain situations #8232

stillhart opened this issue Jul 3, 2020 · 1 comment · Fixed by #8233
Labels

Comments

@stillhart
Copy link

Rubocop replaces end with nd when using rubocop-rails_config

I am not certain whether this bug even belongs into rubocop or into one of the related gems. This bug does not happen if use strictly rubocop without the gem rubocop-rails_config. In the end the decision to change the end to nd is made by rubocop, therefore I assume that it must be a bug in rubocop triggerd by an unusual configuration.

This is the most minimal amount of code to trigger this bug from my current point of view.


Expected behavior

Rubocop should not replace an end with nd in this minimal example:

# user_controller.rb
class UsersController < ApplicationController
  private
end

Actual behavior

Rubocop replaced the end with nd and therefore created invalid code.

# user_controller.rb
class UsersController < ApplicationController
  private
nd

Steps to reproduce the problem

Files

Clone the example repo: rubocop_bug or

# Gemfile
source "https://rubygems.org"
gem "rubocop"
gem "rubocop-rails_config"
# .rubocop.yml                                                                                                                                                                                                                             (master)
inherit_gem:
  rubocop-rails_config:
    - config/rails.yml
# user_controller.rb
class UsersController < ApplicationController
  private
end

To reproduce run:

  • bundle install
  • bundle exec rubocop -a --safe
  • git diff
  • check the git diff output to see if the end in the end of the file was replaced with nd

git diff

diff --git a/user_controller.rb b/user_controller.rb
--- a/user_controller.rb
+++ b/user_controller.rb
@@ -1,3 +1,3 @@
 class UsersController < ApplicationController
   private
-end
+nd

RuboCop version

bundle exec rubocop -V
0.86.0 (using Parser 2.7.1.4, rubocop-ast 0.1.0, running on ruby 2.7.1 x86_64-darwin19)
@koic koic added the bug label Jul 3, 2020
koic added a commit to koic/rubocop that referenced this issue Jul 8, 2020
…ccessModifier`

Fixes rubocop#8232.

This PR fixes a false positive and an incorrect auto-correct for
`Layout/EmptyLinesAroundAccessModifier` when `end` immediately
after access modifier.
bbatsov pushed a commit that referenced this issue Jul 8, 2020
…difier`

Fixes #8232.

This PR fixes a false positive and an incorrect auto-correct for
`Layout/EmptyLinesAroundAccessModifier` when `end` immediately
after access modifier.
@stillhart
Copy link
Author

I just saw that my bug report was fixed very fast. Thank you very much and I appreciate your work.

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