amatiasq / vsc-sort-imports

Sort ES6 imports automatically.
ISC License
57 stars 24 forks source link

Sorting breaks typescript comments #57

Open DrummerSi opened 4 years ago

DrummerSi commented 4 years ago

When given the following import:

import { Client } from "boardgame.io/react";
//@ts-ignore
import { CreateGame } from "boardgame.io/server"

the plugin auto-sorts and removes comments, so it looks like this:

import { Client } from "boardgame.io/react";
import { CreateGame } from "boardgame.io/server"
//@ts-ignore

This will break the the server import though, as there are no typescript definitions for it

amatiasq commented 4 years ago

This is unexpected, the last known behaviour is that the tool assumes a comment above an import is part of the import itself. More info at #20

I cannot reproduce it, I pasted your code in a new file and sorting the imports moves the comment with the import, not below.

Can you disable all other extensions and try again? What sorting style are you using?

DrummerSi commented 4 years ago

I've re-tested it.. Using a new Virtual Machine, a new install of the latest VSCode, and only the 'vsc-sort-imports' plugin installed. All options were left as default. issue still occurs:

See image: https://i.imgur.com/dzvfBvJ.gif

jquense commented 4 years ago

does the same thing happen if you install import-sort-cli (v6) directly and run it against the file?

DrummerSi commented 4 years ago

Indeed, the same thing happens when just running the CLI https://i.imgur.com/daP6i3U.png

amatiasq commented 4 years ago

If the CLI does it too then it's not an issue of this extension but of the core import-sort. I found this issue related, what line endings are you using? can you try with LF line endings?

amatiasq commented 4 years ago

Yes, I can reproduce it by changing my line endings from LF to CRLF.

This issue can be fixed by changing the file line endings to LF.

That said, this should work with any line endings and we should notify renke/import-sort and try to help them fix it.

DrummerSi commented 4 years ago

I never thought about the line endings. Glad we got to the bottom of it.. And I can see you've commented on the open issue you found. Hopefully they can get it fixed soon :)