-
Notifications
You must be signed in to change notification settings - Fork 71
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
Support for namespace imports #144
Comments
Hi! Do you mean that you would like lines like these:
to be sorted, together with other imports? If so, what should we sort on – the thing after the Just as a heads up, I have never seen such imports before, so I’m not very excited about putting work into them. |
@lydell it's not very popular, but type/interface (re)assignment is not the same as deep interface references and currently this is the only way to do it (the linked github post agrees with both you and me, that it is confusing) - but I started working with a huge codebase and this is all over the place, because we have lots of nested, complicated interfaces (at this point I'd say that "if you need it, then PRs are welcome", but there's a very very low chance I'd be able to squeeze something like this into the scrum board). Imo these lines can be left alone, the problem is that the sorter ignores anything that comes after these, and vscode inserts the autoimports after these lines (hence I said it is debatable who should do this). Example: (1) we have this set of imports: import { bar } from './bar-utils';
import foo from 'foolib';
import ICorgi = IAnimal.ICanine.IDog; (2) we start coding and let vscode add an autoimport (qux): import { bar } from './bar-utils';
import foo from 'foolib';
import ICorgi = IAnimal.ICanine.IDog;
import { qux } from './qux-utils'; // <-- newly eddid by editor (3) use autofix (current): import foo from 'foolib';
import { bar } from './bar-utils'; // <-- these are properly sorted
import ICorgi = IAnimal.ICanine.IDog;
import { qux } from './qux-utils'; // <-- this was not touched expected: import foo from 'foolib'; // <-- external lib first
import { bar } from './bar-utils'; // <-- internal code follows
import { qux } from './qux-utils';
import ICorgi = IAnimal.ICanine.IDog; // <-- remains untouched |
FYI the reason this happens is because this plugin sorts “chunks” of imports – import statements in a row. In this case there are two chunks, because the namespace import thingy happens to be a different AST node. I’ll need to think about what to do here. |
Here are some things I’ve learned:
So the same feature supports both the namespace thing mentioned in this issue, and We could support just Another way would be to simply “move them out of the way” (and potentially alphabetizing them). But should they be moved above or below? This also feels a bit random – if you have other statements that aren’t standard imports in between imports, those aren’t moved away (I recommend I could maybe see a future where this plugin moves But I’m currently leaning more towards not making any changes. Instead, you could create your own rule that moves import assignments like you want them. |
Very good points, haven't know about the The other option is that I create a vscode plugin for myself, where I chain format document + sort imports + eslint fix (sort imports moves the bottommost import to the "real" group, eslint fix runs - among other things - your plugin). |
I fixed this problem without adding a lot of code and complex logic. This problem is very urgent for us, we have broken imports for this reason. Other rules support sorting of this type of imports, so it would be nice to add it here as well. |
Released in v11.0.0. (Finally! Sorry for the long delay.) |
Reverted in v12.0.0. |
Nested type declarations can be "deeply imported" in typescript, in a bit awkward syntax, see:
microsoft/TypeScript#39935
Currently both the plugin and the builtin import order rule ignores these lines, which is rather unfortunate, since editors insert autoimports below the last "import-like" line:
An autoimport will insert the new
import { foo } from './foo'
below the last line, which will be ignored by the sorter. Any new imports will land under the last import, further piling up the problematic (unsortable) lines.I can understand, if this can / should be considered a problem with the code editor (vscode in my case) though. What's your opinion?
The text was updated successfully, but these errors were encountered: