-
Notifications
You must be signed in to change notification settings - Fork 25
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
Odd behavior with twin.macro
import
#167
Comments
@therealgilles -- This plugin will not reorganize "side-effect" imports. |
I'm not sure I understand. The plugin is re-organizing its placement by adding blank spacing around it. Why not provide a pragma for side-effect imports, or better allow exact matches in the import list? I would expect this to work for instance: importOrder: [
'',
'^react$',
'^twin.macro$',
'<BUILT_IN_MODULES>',
'<THIRD_PARTY_MODULES>',
'',
'^@/',
'^[.]',
], |
@therealgilles That's not a feature of this plugin. This plugin takes great care to be the least dangerous it can be, and reordering across side-effect imports could break many many projects -- Other import sorting plugins do offer that feature, this plugin chose not to. Making sure not to do so took a lot of code to get right, so that's a huge attractive factor for this plugin. This is why we have the first bullet-point in the README:
A pragma to permit it would be pretty complex code. |
Gotcha! Thanks for taking the time to explain. It is not a big deal anyway. |
I am still surprised the plugin is adding blank lines around the side-effect import. Why is that? |
@therealgilles when you have a side-effect import, we treat the block above the side-effect and the block below the side-effect as independent groups (that are each sorted according to Your The semi-colon is indeed unexpected given what I assume is your prettier config. For myself I always use semi-colons in my code -- it's likely we didn't test that case heavily, but I would have expected prettier to respect your settings. I can tell you that this plugin doesn't directly manipulate semi-colons, we just manipulate Abstract-syntax-tree nodes, and allow babel/prettier to assemble the final output according to your configs e.g. indentation, line lengths, and semi-colons are all handled outside of this plugin. |
Okay got it, I appreciate the detailed explanation, thank you. I am thinking the semi-colon may come from another setting somewhere, or another formatter. |
I ran a couple experiments and the addition of the semi-colon only happens when this plugin is enabled. |
@therealgilles if you're still intersted, would you be willing to create a quick reproduction repo that we can look into? I'm not familiar with twin.macro personally. |
Your Environment
Describe the bug
twin.macro
seems to bother the sort algorithm. This is what it does:To Reproduce
See above and config below.
Expected behavior
I expect this:
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
Here is the
importOrder
:The text was updated successfully, but these errors were encountered: