feat(await-async-query): add auto-fix#917
Closed
neriyarden wants to merge 8 commits into
Closed
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #917 +/- ##
==========================================
+ Coverage 96.27% 96.30% +0.03%
==========================================
Files 46 46
Lines 2472 2493 +21
Branches 1025 1035 +10
==========================================
+ Hits 2380 2401 +21
Misses 92 92 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
MichaelDeBoey
previously approved these changes
Oct 17, 2024
102c81a to
1facfc3
Compare
2 tasks
1facfc3 to
a582606
Compare
MichaelDeBoey
previously approved these changes
Oct 19, 2024
Signed-off-by: Michaël De Boey <info@michaeldeboey.be>
MichaelDeBoey
previously approved these changes
Oct 19, 2024
Contributor
Author
|
@Belco90 @MichaelDeBoey |
Belco90
requested changes
May 5, 2025
| if ( | ||
| isMemberExpression(identifierNode.parent) && | ||
| ASTUtils.isIdentifier(identifierNode.parent.object) && | ||
| identifierNode.parent.object.name === 'screen' |
Member
There was a problem hiding this comment.
Does it really matter if the parent object is screen? I think it should work no matter what's the name of its parent is.
For example:
test("An example test", async () => {
const view = render(<Component />)
const button = view.findByText('submit')
});In this case, view.findByText wouldn't be autofixed, but it should. Can you add this scenario to the tests, and adjust the rule fix accordingly?
Comment on lines
+141
to
+184
| const functionExpression = | ||
| findClosestFunctionExpressionNode(node); | ||
|
|
||
| if (!functionExpression) return null; | ||
|
|
||
| let IdentifierNodeFixer; | ||
| if (isMemberExpression(identifierNode.parent)) { | ||
| /** | ||
| * If the wrapper is a property of an object, | ||
| * add 'await' before the object, e.g.: | ||
| * const obj = { wrapper: () => screen.findByText(/foo/i) }; | ||
| * await obj.wrapper(); | ||
| */ | ||
| IdentifierNodeFixer = fixer.insertTextBefore( | ||
| identifierNode.parent, | ||
| 'await ' | ||
| ); | ||
| } else { | ||
| /** | ||
| * Add 'await' before the wrapper function, e.g.: | ||
| * const wrapper = () => screen.findByText(/foo/i); | ||
| * await wrapper(); | ||
| */ | ||
| IdentifierNodeFixer = fixer.insertTextBefore( | ||
| identifierNode, | ||
| 'await ' | ||
| ); | ||
| } | ||
|
|
||
| if (functionExpression.async) { | ||
| return IdentifierNodeFixer; | ||
| } else { | ||
| /** | ||
| * Mutate the actual node so if other nodes exist in this | ||
| * function expression body they don't also try to fix it. | ||
| */ | ||
| functionExpression.async = true; | ||
|
|
||
| return [ | ||
| IdentifierNodeFixer, | ||
| fixer.insertTextBefore(functionExpression, 'async '), | ||
| ]; | ||
| } | ||
| }, |
1 task
Member
|
Closing due to inactivity. Feel free to reopen to get it merged, fixing the requested changes. |
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checks
Changes
Context
Fixes #914
also some of #202