-
Notifications
You must be signed in to change notification settings - Fork 147
new rule request: prefer-find-by #127
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
Comments
Hello Ben! Thanks for your suggestion. Indeed, this would be a nice addition. Do you want to give it a try? PRs are welcome! I must admit this one could be a hard one to implement tho, as there are plenty of things you can find within |
I wish I could but I'm swamped at work. I noticed we have a lot of them in our code so figured I'd add the issue. :) |
I might be able to take a peek in this one in the incoming days 😄 |
That would be great! Let me know if you want to discuss some details about the rule or its implementation. |
yeah, I have some doubts about being able to fix it in all scenarios... given the callback could potentially have tons of statements - it just seems "feasible" when the statement inside the callback is only one (like a arrow function without brackets, for instance) Thoughts? |
Exactly. We can potentially find anything within callback body passed to One of the latest ESLint features is the ability to suggest fixes. This looks like a good place to try it! But I'd leave it as an optional step at the end, as just implementing the rule and fixing the code for single statements is a lot of work. |
we could also narrow the fix if that statement inside the callback contains an should we also include the deprecated methods (for instance |
That seems a good idea. And actually, let's forget about the possibility of adding suggestions and just focus on single statement within I think it's not difficult to include deprecated wait utils when it's done for waitFor, so I'd add them too. |
I created a draft PR for this one. After giving some thought and reading the best practice mentioned by kent c dodds I simplified a bit the approach: The rule should not check for Basically, this scenario await waitFor(/* some sync query */) The example he provided is const submitButton = await waitFor(() =>
screen.getByRole('button', {name: /submit/i}),
) and the proper "correct" version should be const submitButton = await screen.findByRole('button', {name: /submit/i}) Thoughts? as there are no assertions inside, I think this one has more chances of being automatically fixed. I will check it out (perhaps for the same PR, perhaps in a 2nd one) |
Oh yeah. Sorry for not leaving it clear, but here we only need to check single statement within So your approach is absolutely fine. |
🎉 This issue has been resolved in version 3.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
as described in Kent's blog post, it would be nice to have an autofix rule that converts
into this:
The text was updated successfully, but these errors were encountered: