-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import/order doesn't sort assets that aren't assigned to a variable (e.g. import './file.css'
)
#1639
Comments
Imports without a binding are used for side effects. As such, no bindingless import should ever be moved with an autofixer, and no import-with-a-binding should ever be autofixed such that it runs in a different order with respect to a bindingless import. |
Is there a way to configure this differently? I essentially want to enforce grouping all css files together, and all gif|png|jpg|json files together. |
It’s not safe to have a rule that does that. Bindingless imports only exist for side effects, and ordering is critical with side effects. |
Your arguments are correct for complicated cases, but it would be nice if you could optionally configure to do something with the side-effect-only imports. I'm currently using a vscode plugin (TypeScript Import Sorter) that puts them on the top, in a separate group, plus a tslint rule that checks that. IMHO side-effect imports should be used cautiously and only if absolutely necessary, so
I'm using side-effect imports only for "global" stuff like |
I totally agree that it’s a smell - but a rule that risks making people do the wrong thing, without knowing why, isn’t a good rule. It might be possible to make this warnable, but never to make it autofixable. |
maybe suggestions can be used here as they are not automatically applied https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions |
I would be very open to adding suggestions to all non-autofixable warnings in the plugin regardless :-) |
@ljharb The fix here is relatively easy if we want to just warn on out of order imports. We are ignoring adding them to the check. The hard part I need an expert to weigh in on is how we want to make the fix. Should we start warning (and not autofixing) on all out of order unassigned imports with default options? Or should I add a new option like |
@Alphy11 it should definitely require a new option, otherwise it's a breaking change. |
…s for out of order unassigned imports Fixes import-js#1639
When sorting imports, any assets that aren't assigned to a variable are ignored, and break/mess with sorting of other imports.
e.g.
If I change the above and assign assets to a variable, sorting is applied as expected.
The text was updated successfully, but these errors were encountered: