-
Notifications
You must be signed in to change notification settings - Fork 148
feat(prefer-find-by): make the rule fixable #153
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(prefer-find-by): make the rule fixable #153
Conversation
So I think that scenario should be fixed too. |
context.report({ | ||
node, | ||
messageId: "preferFindBy", | ||
data: { queryVariant, queryMethod, fullQuery }, | ||
fix(fixer) { | ||
const newCode = `${caller ? `${caller}.` : ''}${queryVariant}${queryMethod}(${callArguments.map((node) => sourceCode.getText(node)).join(', ')})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, even checking the test I can't figure out how this replaces waitFor
+ getBy
with findBy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that mean is it too obscure? 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I just realized queryVariant
is the corresponding findBy from getFindByQueryVariant
, rather than the original query variant found in the code as I thought. Could you add a simple jsdoc to reportInvalidUsage
to clarify what args are expected? Probably would be a good idea to add more jsdoc around the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to write a suggestion for this jsdoc? We need something simple, not elaborated description necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you want. I can do it, but I will probably do it in the weekend as I have some work to do 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, there is no rush around this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! It wasn't even necessary to re-add the type, but thanks!
yeah, I felt the same. The PR fixes that scenario as well 🎉 |
context.report({ | ||
node, | ||
messageId: "preferFindBy", | ||
data: { queryVariant, queryMethod, fullQuery }, | ||
fix(fixer) { | ||
const newCode = `${caller ? `${caller}.` : ''}${queryVariant}${queryMethod}(${callArguments.map((node) => sourceCode.getText(node)).join(', ')})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I just realized queryVariant
is the corresponding findBy from getFindByQueryVariant
, rather than the original query variant found in the code as I thought. Could you add a simple jsdoc to reportInvalidUsage
to clarify what args are expected? Probably would be a good idea to add more jsdoc around the plugin.
bee49db
to
f8050b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to go! 🚀
context.report({ | ||
node, | ||
messageId: "preferFindBy", | ||
data: { queryVariant, queryMethod, fullQuery }, | ||
fix(fixer) { | ||
const newCode = `${caller ? `${caller}.` : ''}${queryVariant}${queryMethod}(${callArguments.map((node) => sourceCode.getText(node)).join(', ')})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! It wasn't even necessary to re-add the type, but thanks!
🎉 This PR is included in version 3.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This feature extends prefer-find-by rule to make it fixable
One doubt I had was whether to fix or not this scenario
as
queryBy*
methods do not throw if not found, butfindBy*
do. At first I thought of not changing the behavior, but then I consider that if null was always returned, eventuallywaitFor
would timeout, throwing as well (just like thefindBy*
method would)