-
Notifications
You must be signed in to change notification settings - Fork 236
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
fix(prefer-importing-jest-globals): don't add imports in the middle of statements #1645
fix(prefer-importing-jest-globals): don't add imports in the middle of statements #1645
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.
could you undo all the unneeded indenting changes in the test cases please?
dbb9a35
to
ecec8dc
Compare
Oh yikes, yeah, clearly prettier did not have my back. |
ecec8dc
to
090fd91
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.
this looks fine, though I'd appreciate if you could cleanup the intending on the new cases (sorry, Prettier doesn't handle javascript-in-javascript blocks 😅) and explain a bit more about
Why didn't I just put the import at the top in both cases? Because it would have broken a couple of tests, eg:
I don't follow how it would have broken the test you've mentioned
That test places the |
What matters for us (mostly) is if its syntactically valid e.g. if we would end up duplicating a We still do some of that stuff when it's easy because it can still be nice to do, but if a particular thing is very complex then we can choose not to take on that complexity. In this case though I think putting it at the top of the file is the right move as it's likely we'll have multiple references throughout nested functions, though I think we should be fine to just always put the require at the very top of the file like you're doing for |
… the middle of a statement
…ame import behaviour
2f99c06
to
f33e4d9
Compare
## [28.8.3](v28.8.2...v28.8.3) (2024-09-04) ### Bug Fixes * **prefer-importing-jest-globals:** don't add imports in the middle of statements ([#1645](#1645)) ([9c4197c](9c4197c))
🎉 This issue has been resolved in version 28.8.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
The current fixer implementation for prefer-importing-jest-globals inserts the
import
directly before the reporting node. This works fine when the reporting node is a function call.results in
But it breaks when the reporting node is part of a variable declaration
results in
This change updates the fixer so new imports are inserted at the top of the file.
results in
Existing imports are unchanged
results in
Resolves #1634