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

[Fix #8781] Change how comments are determined for Style/SafeNavigation autocorrection #8813

Merged
merged 1 commit into from Oct 17, 2020

Conversation

dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Sep 29, 2020

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.

I had tried looking into Parser::Source::Comment.associate_locations as a way to determine what node each comment belonged to, but this does not associate comments in the way we're expecting for this cop.

Fixes #8781.


Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@dvandersluis dvandersluis force-pushed the issue/8781 branch 3 times, most recently from 3ea5d89 to 9c64fb4 Compare October 3, 2020 18:19
CHANGELOG.md Outdated
@@ -16,6 +16,9 @@
* [#8354](https://github.com/rubocop-hq/rubocop/issues/8354): Detect regexp named captures in `Style/CaseLikeIf` cop. ([@dsavochkin][])
* [#8830](https://github.com/rubocop-hq/rubocop/issues/8830): Fix bad autocorrect of `Style/StringConcatenation` when string includes double quotes. ([@tleish][])
* [#8807](https://github.com/rubocop-hq/rubocop/pull/8807): Fix a false positive for `Style/RedundantCondition` when using assignment by hash key access. ([@koic][])
* [#8810](https://github.com/rubocop-hq/rubocop/pull/8810): Fix multiple offense detection for Style/RaiseArgs. ([@pbernays][])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are those entries coming from? Probably you need to rebase.

@dvandersluis
Copy link
Member Author

@bbatsov I'm not sure! I think I probably caught them in a previous rebase and didn't realize it. I've fixed it up now, thanks.

@dvandersluis dvandersluis force-pushed the issue/8781 branch 3 times, most recently from 35984e3 to c425549 Compare October 9, 2020 17:15
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 16, 2020

Can you rebase again please?

…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.
@dvandersluis
Copy link
Member Author

@bbatsov done!

@bbatsov bbatsov merged commit 837899c into rubocop:master Oct 17, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 17, 2020

Thanks!

@dvandersluis dvandersluis deleted the issue/8781 branch January 18, 2021 20:42
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.

Style/SafeNavigation auto-correct duplicates comments
2 participants