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

autoformat deleting comments #10920

Closed
mutantcows opened this issue Aug 13, 2022 · 0 comments · Fixed by #10923
Closed

autoformat deleting comments #10920

mutantcows opened this issue Aug 13, 2022 · 0 comments · Fixed by #10923
Labels

Comments

@mutantcows
Copy link

When rubocop autocorrect detects Style/NestedConditional with a comment before and after, it inadvertantly deletes the trailing comment.


Steps to reproduce the problem

test.rb

if var1
  # first important comment
  if var2
    # second important comment
  end
end

rubocop -a test.rb

test.rb

if var1 && var2
  # second important comment
end

RuboCop version

Both 1.32 and 1.35

1.32.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.2 x64-mingw-ucrt)
1.35.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.2 x64-mingw-ucrt)
@koic koic added the bug label Aug 15, 2022
koic added a commit to koic/rubocop that referenced this issue Aug 15, 2022
…dConditional`

Fixes rubocop#10920.

This PR fixes an incorrect autocorrect for `Style/SoleNestedConditional`
when using nested conditional and branch contains a comment.

It removes `return if config.for_cop('Style/IfUnlessModifier')['Enabled']` that introduced in rubocop#9195.
That logic is now unnecessary due to rubocop@3fea162 change.
koic added a commit that referenced this issue Aug 16, 2022
…style_sole_nested_conditional

[Fix #10920] Fix an incorrect autocorrect for `Style/SoleNestedConditional`
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