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 #9622] Fixed Style/BisectedAttrAccessor autocorrection to handle multiple bisected attrs in the same macro #9634

Merged
merged 1 commit into from Mar 24, 2021

Conversation

dvandersluis
Copy link
Member

This ended up being a pretty heavy refactor of the Style/BisectedAttrAccessor cop.

Previously we were doing multiple passes at determining what macros are relevant for the cop, and which names within them. Despite that, if a macro had multiple names and was rewritten, we'd lose context of what other names there were and only the first one would survive the autocorrection.

Instead, I have now extracted a Macro value object that encapsulates all the data for the macro, including visibility (since macros of different visibilities are not combined), bisected and non-bisected attribute names, etc. When investigating a class, any macros found have objects created, and they are retained to be used to correct the class as a whole after wards (but we still register offenses on individual macro attributes as before).

I have also added some more edge case tests that I encountered as I was working on this.

Fixes #9622.


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.

@dvandersluis dvandersluis force-pushed the issue/9622 branch 3 times, most recently from 3ddc5e5 to 2710e13 Compare March 23, 2021 19:52
@koic
Copy link
Member

koic commented Mar 24, 2021

Great work! Can you add a changelog entry?

@dvandersluis
Copy link
Member Author

@koic 🤦🏻‍♂️ I knew I forgot something. Thanks!

…to handle multiple bisected attrs in the same macro.
@bbatsov bbatsov merged commit 56d645d into rubocop:master Mar 24, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 24, 2021

Great work! 🏅

@dvandersluis dvandersluis deleted the issue/9622 branch September 14, 2021 16:04
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/BisectedAttrAccessor AutoCorrect fails when multiple variables are defined
3 participants