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

feat: add prefer-query-matchers rule #750

Merged
merged 9 commits into from May 10, 2023

Conversation

CodingItWrong
Copy link
Contributor

@CodingItWrong CodingItWrong commented Apr 4, 2023

Checks

Changes

  • Adds prefer-query-matchers rule, with tests and docs

Context

Fixes #728

@CodingItWrong
Copy link
Contributor Author

HT @obsoke who paired with me on all this work.

@Belco90 if you get a moment, could you review what we've written so far to see if it seems to be on the right track? We appreciate it!

@CodingItWrong CodingItWrong force-pushed the pr/prefer-query-matchers branch 3 times, most recently from 9c512a4 to 44850ff Compare April 11, 2023 12:15
@CodingItWrong CodingItWrong marked this pull request as ready for review April 11, 2023 12:15
@CodingItWrong
Copy link
Contributor Author

CodingItWrong commented Apr 11, 2023

@Belco90 Ready for review!

As we worked on this, we thought of another options schema idea. With the current API, there is some repetition if you have a lot of configured entries:

{
  "validEntries": [
    {"matcher": "toBeA", "query": "get"},
    {"matcher": "toBeB", "query": "query"},
    {"matcher": "toBeC", "query": "get"},
    {"matcher": "toBeD", "query": "query"},
    {"matcher": "toBeE", "query": "get"},
    {"matcher": "toBeF", "query": "query"},
  ]
}

It might reduce repetition in the options if we group the get and query matchers:

{
  "getMatchers": ["toBeA", "toBeC", "toBeE"],
  "queryMatchers": ["toBeB", "toBeD", "toBeF"]
}

Please let us know if you'd like us to make that change; it would be quick.

@MichaelDeBoey MichaelDeBoey marked this pull request as draft April 11, 2023 14:32
@Belco90
Copy link
Member

Belco90 commented Apr 11, 2023

@CodingItWrong makes sense! I'll try to review it by the end of the month.

@CodingItWrong
Copy link
Contributor Author

CodingItWrong commented Apr 11, 2023

Thanks @Belco90!

@MichaelDeBoey was changing this PR to draft intentional? If so, could you provide some rationale? In my understanding it's complete and ready to review and merge.

EDIT: I just noticed that the PR description was out of date, and still referred to a draft and work remaining to be done. I've now edited the description to correctly indicate that that work is done.

@obsoke
Copy link
Contributor

obsoke commented Apr 11, 2023

Hello! I worked on this rule with @CodingItWrong.

We were wondering if it made sense for this rule to come with a default configuration. This default would ensure that the matcher .toBeVisible was attached to a get query. After all, this was the motivation (see #728) for creating this rule in the first place. I know I've personally made the mistake of pairing a query* query with toBeVisible before. An ESLint rule letting me know what I did wrong would have been helpful.

@CodingItWrong
Copy link
Contributor Author

@MichaelDeBoey I've moved this PR back out of draft as my intention is that it's ready for review, and you haven't given a reason it should be in draft instead. If you do think it needs to be a draft, please provide a reason—thank you.

@CodingItWrong CodingItWrong marked this pull request as ready for review April 12, 2023 11:08
@MichaelDeBoey MichaelDeBoey changed the title DRAFT: Add prefer-query-matchers rule feat: add prefer-query-matchers rule Apr 12, 2023
@Belco90
Copy link
Member

Belco90 commented Apr 26, 2023

@CodingItWrong thanks for your patience! I'm slowly catching up, so I hope I can review it soon.

@CodingItWrong
Copy link
Contributor Author

@Belco90 No worries! I just fixed the style issue that CI was reporting. I'll keep an eye on any other failures to address them.

@CodingItWrong
Copy link
Contributor Author

@Belco90 BTW we see that the branch is out-of-date with main. We are thinking we will wait until review to update it, but if you need us to do that in advance please let us know

Is there an easy way to pre-approve CI to rerun after any fix I push up? If so that would allow us to resolve issues in advance

@Belco90
Copy link
Member

Belco90 commented May 8, 2023

@Belco90 BTW we see that the branch is out-of-date with main. We are thinking we will wait until review to update it, but if you need us to do that in advance please let us know

Is there an easy way to pre-approve CI to rerun after any fix I push up? If so that would allow us to resolve issues in advance

I'm afraid there isn't! Any way of automating it would lead to the same issue that restriction prevents.

Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

It was really easy to follow the implementation of the rule, great job! I've seen you used a couple of existing helpers, I hope that made working with the codebase easier.

I just asked for a change to improve the code scenarios of the tests, everything else LGTM. It would be nice to also catch asserts with elements queried before the assertion, but it's fine for this first implementation.

Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you both for your contribution!

@Belco90 Belco90 merged commit 31516ad into testing-library:main May 10, 2023
26 checks passed
@Belco90
Copy link
Member

Belco90 commented May 10, 2023

It might reduce repetition in the options if we group the get and query matchers:

{
  "getMatchers": ["toBeA", "toBeC", "toBeE"],
  "queryMatchers": ["toBeB", "toBeD", "toBeF"]
}

Please let us know if you'd like us to make that change; it would be quick.

I think I forgot to answer to this, I just realized now… I think for the first implementation of the rule is fine like the current one (although it can cause tons of entries in the options). Still, we can implement this alternative way of configuring it living together with the current implementation.

@github-actions
Copy link

🎉 This PR is included in version 5.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Belco90
Copy link
Member

Belco90 commented May 10, 2023

@all-contributors
please add @CodingItWrong for code, test, docs, and ideas

@CodingItWrong
Copy link
Contributor Author

@Belco90 would you mind adding @obsoke for test and docs as well? i may not have reflected in the commit attribution correctly, but we wrote all three of those while actively pairing

@Belco90
Copy link
Member

Belco90 commented May 10, 2023

@all-contributors please add @obsoke for code, test, and docs

@allcontributors
Copy link
Contributor

@Belco90

I've put up a pull request to add @CodingItWrong! 🎉

I've put up a pull request to add @obsoke! 🎉

@allcontributors
Copy link
Contributor

@Belco90

I've updated the pull request to add @obsoke! 🎉

@Belco90
Copy link
Member

Belco90 commented May 11, 2023

@all-contributors please add @obsoke for code, test, and docs

@allcontributors
Copy link
Contributor

@Belco90

I've put up a pull request to add @obsoke! 🎉

@github-actions
Copy link

github-actions bot commented Aug 5, 2023

🎉 This PR is included in version 6.0.0-alpha.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

@CodingItWrong CodingItWrong deleted the pr/prefer-query-matchers branch March 7, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a rule to support enforcing getBy* for toBeVisible
3 participants