corneliusio / svelte-sublime

💡Sublime Text syntax highlighting for Svelte components
MIT License
58 stars 6 forks source link

Unwanted reformatting on save #28

Closed p-mercury closed 1 year ago

p-mercury commented 1 year ago

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 1 year ago

@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 1 year ago

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 1 year ago

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 1 year ago

@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 1 year ago

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.

corneliusio commented 1 year ago

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