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

Improve comments handling in couple of auto-corrections #9338

Merged
merged 2 commits into from
Jan 7, 2021

Conversation

Darhazer
Copy link
Member

@Darhazer Darhazer commented Jan 6, 2021

I learned the hard way that the comments_before_line won't stop until the very first line in the processed file, and that it doesn't care whether the comments begin their own line or not. So I replaced it in the 2 cops that use it.

In one of them (that uses the CommentsHelp mixin) the code already tried to limit the damage by looking for consecutive lines, so it would only break if there is a node with inline comment and missing separating line.

The other one however would completely mess the comments, bringing all of the unrelated one to the new position, so I added spec for that case. It also fixes #9233


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

…ocorrection

Previously it would gather all comments up to the root node, bringing non-relevant comments to the if node.
Previously it would take nodes that have inline comment as well,
as long as a blank line to separate the node from the one that would be extracted is missing.
@bbatsov bbatsov merged commit a2d7e0a into master Jan 7, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 7, 2021

Looks good! Thanks!

@bbatsov bbatsov deleted the improve-comments-handling branch January 7, 2021 07:45
@koic
Copy link
Member

koic commented Jan 7, 2021

Thank you @Darhazer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong auto correction Style/SoleNestedConditional
3 participants