Fixed the order of arguments for Prettier with svelte #381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #375. When making changes and then saving an unsaved buffer (like one would do with a BufWritePre autocmd to format on save) on a Svelte file the changes that haven't yet been saved get undone.
I noticed the Svelte formatter used a different order of prettier arguments than all of the other formatters that use prettier. The
--stdin-filepath
argument had a couple other arguments before the file path. I reordered them so the file path immediately follows--stdin-filepath
and that seems to have fixed the issue for me.I'm pretty sure what's happening is that Prettier ignores the buffer passed as stdin because it doesn't see the file path in the arguments as the value to
--stdin-filepath
, but instead as the file path to the file to format, so it just ignores the buffer text sent over stdin and loads the file from the filesystem which naturally won't have the buffer's changes as they haven't been saved yet. (You can see this by running the commands in the two different orders with--loglevel debug
to see what it interpreted the cli arguments as.)The current order is doing something like this:
The changed order is doing something like this: