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

Style/SafeNavigation auto-correct duplicates comments #8781

Closed
vlad-pisanov opened this issue Sep 24, 2020 · 1 comment · Fixed by #8813
Closed

Style/SafeNavigation auto-correct duplicates comments #8781

vlad-pisanov opened this issue Sep 24, 2020 · 1 comment · Fixed by #8813
Labels

Comments

@vlad-pisanov
Copy link
Contributor

vlad-pisanov commented Sep 24, 2020

When auto-correcting Style/SafeNavigation offenses of code described below, comments are duplicated and the original comments are not properly indented.

Consider:

if x
  x.each do
    # Comment
  end
end

Expected behavior

x&.each do
    # Comment
end

Actual behavior

# Comment
x&.each do
    # Comment
end

Steps to reproduce the problem

Run sample code

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

0.91.1 (using Parser 2.7.1.4, rubocop-ast 0.4.2, running on ruby 2.4.5 x86_64-darwin19)
@koic
Copy link
Member

koic commented Sep 24, 2020

Comment indentation is probably expected to be resolved by Layout/CommentIndentation. Can you enable Layout/CommentIndentation?

@bbatsov bbatsov added the bug label Sep 25, 2020
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Oct 16, 2020
…Navigation` autocorrection.

Previously, every comment within the source range of the `if` being auto-corrected was captured and moved above the rewritten line. This resulted in comment duplication, as some comments belonged to internal blocks within the if. This change only considers line ranges between internal if blocks as entry points for comments that are allowed to be moved.
bbatsov pushed a commit that referenced this issue Oct 17, 2020
…ion` autocorrection.

Previously, every comment within the source range of the `if` being auto-corrected was captured and moved above the rewritten line. This resulted in comment duplication, as some comments belonged to internal blocks within the if. This change only considers line ranges between internal if blocks as entry points for comments that are allowed to be moved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants