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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update README to show more options for disabling and overrides #165
Conversation
The new feature of disabling with empty array can do more than just disabling globally and enabling for certain folders or files. It can do the opposite: enabling globally and disabling for certain folders or file. It can also do sort order overrides, where a different order applies to certain folders and files instead of the global order.
BTW: Would specifying |
Thanks for the contribution. And yes, |
@ADTC question about this: I have the following config: {
"endOfLine": "auto",
"importOrder": ["^@/(.*)$", "^[./]"],
"importOrderParserPlugins": ["typescript", "jsx", "decorators-legacy"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
"overrides": [
{
"files": "**/*.spec.ts*",
"options": {
"importOrder": []
}
}
],
"printWidth": 120,
"proseWrap": "always",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
} And I have a test file named const myMock = jest.fn();
jest.mock('src/dependency/used/by/MyModule', () => { /* ... */ });
// import stuff
// import MyModule (jest.mock above would capture the dependency imported by this guy)
it('my tests', () => { /* ... */ }); Now, even with the |
@farzadmf this plugin is set to hoist import expressions up to the top of the file. You probably want to disable this plugin on files that use |
I believe jest.mock hoists itself to the top no matter where it is when the file is run. That's because in general, imports are always evaluated first even if other code is above it. Maybe you can open a new issue about the exclusion pattern not working? |
Thank you both @IanVS and @fbartho for your replies.
That's what I'm trying to do actually 馃槅 . Although I'm pretty sure it's something I'm missing because I'd be surprised if people using
I can do that for sure; wanted to first confirm if I'm doing it properly or not, and what I expect to happen is what should happen
You lost me on this one 馃槤 , you said:
So, then, what's happening here? That being said, I must say I'm not super familiar with Here's my situation:
Please let me know if there's a better way to do this so that I can keep the |
This isn't really the best place to debug jest issues. I'd suggest reading https://jestjs.io/docs/manual-mocks#using-with-es-module-imports, and if you're trying to run jest in experimental ESModule mode, then it seems not to be supported and you might want to consider migrating to vitest instead, which has much better ESM support. Bottom line, is that sorting does not impact |
You're absolutely right; sorry about that; a bit of a desparate measure 馃檪
Was honestly debating about that; now that you mentioned it, I will check it out And, just in case of a 0.0001% chance that someone might face the same issue as me:
This way, the Thank you again @IanVS for the help and the great plugin |
I apologize that I'm not of much help here. I think this discussion is better moved to a separate issue, rather than in this PR. Thank you though. 馃檪 |
The new feature of disabling with empty array can do more than just disabling globally and enabling for certain folders or files. It can do the opposite: enabling globally and disabling for certain folders or files. It can also do sort order overrides, where a different order applies to certain folders and files instead of the global order.
Feel free to suggest a rewrite of the text if needed. 馃檪 I have used the reverse configuration in an actual project and it works well:
Tip: The
overrides
order can come before or after the globalimportOrder
. It doesn't matter as Prettier will always apply the override regardless of where it is in.prettierrc
.