-
Notifications
You must be signed in to change notification settings - Fork 237
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(valid-expect): supporting automatically fixing adding async in some cases #1579
Conversation
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.
looks like a good start, but this isn't quite the right approach to being incremental 😅 - a fix should address the full issue.
What I meant by incremental is landing a fixer for e.g. expect.extend
or functions without any nesting or a single expect, then digging into advanced cases like "what if you have a function within your test function?"; but also you don't have to do it like that either - if you want to tackle more in a single PR that's great! based on what you've done here for example, I think you might just need to switch to returning an array of fixes and then this might be landable
I misunderstood the concept of incremental improvement. |
I'm encountering a situation where the logic to add 'await' to all expects isn't functioning correctly when there are multiple asynchronous expectations. |
@y-hsgw push up your code and I can take a look. That also sounds like a good example of where we might want to be interactive: if you're having trouble with the fixing, consider focusing on having it just bail out instead for now. |
I might have misunderstood. It's likely that the following sequence of fixes will occur: |
@y-hsgw I think you might be misunderstanding - that relates to when there are conflicts:
The fixer works by taking (via the return) an array of fix operations to apply which make up a single fix - if there is only one operation, then you can just return that but you can think about it as being an array of operations at all times. So when those docs talk about "applying all fixes" and "applies only the first fix" they're referring to the high-level fix aka "a collection of fix operations", which is what you're building here - the issue is right now you're returning two seperate fix operations depending on conditions, when you want to be returning a single array with both operations added conditionally depending on if they're needed for the particular code under lint. |
@G-Rath 2024-05-10.22.04.36.mov |
Yes because as the tests show via the It should be very trivial to return a single array too :) |
This reverts commit e652a25.
@y-hsgw my guess is that it's because you're adding the I would recommend focusing on a single test (you can add |
This reverts commit ae8ecac.
pushPromiseArrayException(finalNode.loc); | ||
} | ||
}, | ||
'Program:exit'() { |
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.
src/rules/valid-expect.ts
Outdated
@@ -4,7 +4,9 @@ | |||
*/ | |||
|
|||
import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils'; | |||
import type { RuleFix } from '@typescript-eslint/utils/ts-eslint'; |
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.
can you pull this type from TSESTree
(or it might be TSESLint
- either way, you can access it through the @typescript-eslint/utils
import)
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.
Thanks! Fixed in 3b27d09.
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 stuff! 🎉
hmm
For some reason the |
🎉 This PR is included in version 28.6.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #1140