prettier-plugin-sort-imports
prettier-plugin-sort-imports copied to clipboard
Removes all line breaks in Svelte
Summary
The problem is as stated in the title: when formatting with this plugin, all line breaks disappear.
Actual behavior
<script>
import Component from './Component.js'
import { onMount } from 'svelte'
onMount(() => {
// --snip--
})
</script>
Expected behavior
<script>
import Component from './Component.js'
import { onMount } from 'svelte'
onMount(() => {
// --snip--
})
</script>
If there are more line breaks, either between imports or normal lines of code, they are all deleted.
The same happens in .vue files.
Not only line breaks, but also mangles comments before:
<script lang="ts">
import poop from './poop';
import noop from './noop';
// Comment one
let someProp: string = "";
// Comment two
let anotherProp: string = "";
</script>
<main />
after:
<script lang="ts">
import noop from "./noop";
import poop from "./poop";
';
// Comme
let someProp: string = "";
";
// Comme
let anotherProp: string = "";
</script>
<main />
see minimal repro: https://github.com/Sharsie/prettier-plugin-sort-imports-svelte-repro
Is this issue still valid? I just applied the plugin to a svelte project, and it did do anything bad regarding line breaks on first glance.
Also, you probably mean "remove all empty lines", not literally "removes all line breaks", right? After all, code block in the actual behavior certainly contains line breaks.
@bluenote10 I updated the minimal repro to v4 and can confirm both issues appear to be still present.
Original:
<script lang="ts">
import poop from './poop';
import noop from './noop';
onMount(() => {
// --snip--
})
// Comment one
let someProp: string = "";
// Comment two
let anotherProp: string = "";
</script>
<main />
With the plugin:
<script lang="ts">
import noop from "./noop";
import poop from "./poop";
onMount(() => {
{
// -
});
})
// Comm
let someProp: string = "";
";
// Comm
let anotherProp: string = "";
</script>
<main />
Without the plugin:
<script lang="ts">
import poop from "./poop";
import noop from "./noop";
onMount(() => {
// --snip--
});
// Comment one
let someProp: string = "";
// Comment two
let anotherProp: string = "";
</script>
<main />
@Sharsie I cannot reproduce the problem: This is how your code looks for me after formatting:

And this is the commit where applied import ordering in one of my projects: https://github.com/bluenote10/guitar-scales-trainer/commit/95bc1659a1d8790c7538b50d93d668b6c39a1a75
Comparing your reproduction repo with my repo I noticed a few differences:
- I'm using newer versions of
prettierandprettier-plugin-svelte. - My npm script for formatting is
prettier --plugin-search-dir . --write .which is what the default svelte kit template comes with.
Not sure if this could explain the difference?