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

refactor: define node matchers on assertion classes #1793

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Jan 30, 2024

I figured this would be enough but didn't want to overload #1790.

It does send the fixer for InternalAffairs/NodeMatcherDirective into an inf. loop though - it looks like one part of the cop sees just the "self" whereas the other sees the whole definition, so it reports "use self.match_assertion instead of self" and then the fixer just keeps adding .match_assertion to the end of the string until it errors; for now I've just disabled it, but I might try and look into it at some point.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • Added the new cop to config/default.yml.
  • The cop is configured as Enabled: pending in config/default.yml.
  • The cop is configured as Enabled: true in .rubocop.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.
  • Set VersionAdded: "<<next>>" in default/config.yml.

If you have modified an existing cop's configuration options:

  • Set VersionChanged: "<<next>>" in config/default.yml.

@G-Rath G-Rath requested a review from a team as a code owner January 30, 2024 17:54
name = m.name.split('::').last

public_send("minitest_#{name}".to_sym, node) do |*args|
m.match_assertion(node) do |*args|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

at this point the names are getting a little silly - I'll next explore if we can nicely have the classes handle calling their match logic and just return a result

@bquorning
Copy link
Collaborator

@G-Rath I pushed an alternative implementation at the same time as you opened your PR: #1794. I hadn’t considered using class methods for the node matchers, that’s a neat idea.

@bquorning bquorning merged commit f8e0611 into rubocop:master Jan 31, 2024
24 checks passed
@G-Rath G-Rath deleted the refactor-again branch January 31, 2024 22:12
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.

2 participants