Unwanted reformatting on save #28

Closed
opened 2023-06-27 20:11:52 +00:00 by p-mercury · 6 comments
p-mercury commented 2023-06-27 20:11:52 +00:00 (Migrated from github.com)

I am using the Js​Prettier plugin to format all of code but it is conflicting with the auto formatting done by this package. I am not sure why but this plugin reformats the svelte file on save. I don't expect this behaviour of a syntax highlighter and can see a way of turning it off.

One example of this automatic formatting is that the prettier-plugin-svelte wants anything inside of a conditional render to be indented:

{#if !data.user}
  <div>test<div>
{/if}

But when I have this plugin installed, the plugin seems to remove this indentation on save:

{#if !data.user}
<div>test<div>
{/if}

Since I run prettier as a precommit hook I always run into an error because the plugin is overriding the Js​Prettier plugins changes.

Since this is meant to be a syntax highlighter I would suggest removing this, or at least adding a setting to disable it.

I am using the `Js​Prettier` plugin to format all of code but it is conflicting with the auto formatting done by this package. I am not sure why but this plugin reformats the svelte file on save. I don't expect this behaviour of a syntax highlighter and can see a way of turning it off. One example of this automatic formatting is that the `prettier-plugin-svelte` wants anything inside of a conditional render to be indented: {#if !data.user} <div>test<div> {/if} But when I have this plugin installed, the plugin seems to remove this indentation on save: {#if !data.user} <div>test<div> {/if} Since I run prettier as a precommit hook I always run into an error because the plugin is overriding the `Js​Prettier` plugins changes. Since this is meant to be a syntax highlighter I would suggest removing this, or at least adding a setting to disable it.
corneliusio commented 2023-06-27 21:25:34 +00:00 (Migrated from github.com)

@p-mercury Hmm, so this plugin does not do any sort of auto-formatting or writing to any project files whatsoever. Whatever issue you're seeing here, it can't be caused by this plugin.

@p-mercury Hmm, so this plugin does not do any sort of auto-formatting or writing to any project files whatsoever. Whatever issue you're seeing here, it can't be caused by this plugin.
p-mercury commented 2023-06-29 09:26:54 +00:00 (Migrated from github.com)

That is very strange, I'll do a bit of investigation to see whats happening. The reason I suspect something with this package is that when I disable it in the package manager and then press save on the file, prettier adds back in the lost indentation.

That is very strange, I'll do a bit of investigation to see whats happening. The reason I suspect something with this package is that when I disable it in the package manager and then press save on the file, prettier adds back in the lost indentation.
p-mercury commented 2023-06-29 10:13:13 +00:00 (Migrated from github.com)

I can't seem to figure out what is causing this, whenever I have this plugin enabled prettier (with the svelte extension) removes certain indentation like shown in the initial. If someone else can figure it out please let me know.

I can't seem to figure out what is causing this, whenever I have this plugin enabled prettier (with the svelte extension) removes certain indentation like shown in the initial. If someone else can figure it out please let me know.
corneliusio commented 2023-06-29 13:35:43 +00:00 (Migrated from github.com)

@p-mercury If I had to guess, I'd say you likely have a plugin that's applying formatting based on file scope and/or syntax. When you have this plugin installed your file will have a scope of text.html.svelte and a syntax of Svelte. Otherwise, these files would just be HTML or Plain Text and potentially treated differently on save than when you have this plugin installed. It's possible prettier-plugin-svelte itself is treating these files differently based on scope and/or syntax or there is another plugin in the mix that's causing this. But again, this package is just a .sublime-syntax file so there's no way this plugin is the actual root issue.

@p-mercury If I had to guess, I'd say you likely have a plugin that's applying formatting based on file scope and/or syntax. When you have this plugin installed your file will have a scope of `text.html.svelte` and a syntax of `Svelte`. Otherwise, these files would just be HTML or Plain Text and potentially treated differently on save than when you have this plugin installed. It's possible `prettier-plugin-svelte` itself is treating these files differently based on scope and/or syntax or there is another plugin in the mix that's causing this. But again, this package is just a `.sublime-syntax` file so there's no way this plugin is the actual root issue.
p-mercury commented 2023-06-29 14:53:53 +00:00 (Migrated from github.com)

Thank you very much for pointing that out, that helped me find a solution.

This issue describes the same issue but with LiquidJS and has a solution.

Thank you very much for pointing that out, that helped me find a solution. This [issue](https://github.com/jonlabelle/SublimeJsPrettier/issues/267) describes the same issue but with LiquidJS and has a solution.
corneliusio commented 2023-06-29 15:44:16 +00:00 (Migrated from github.com)

@p-mercury Fantastic! Glad you were able to get down to the root of it.

@p-mercury Fantastic! Glad you were able to get down to the root of it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
repos/svelte-sublime#28
No description provided.