vscode-liquid icon indicating copy to clipboard operation
vscode-liquid copied to clipboard

Formatting Overridden by Prettier

Open entozoon opened this issue 4 years ago • 4 comments

If you use Prettier, its HTML formatting trumps this plugin and makes a huge hot mess. There is a workaround which is that you can set your workspace settings along the lines of

{  
  "settings": {
    "editor.formatOnSave": true,
    "[html]": {
      "editor.defaultFormatter": "sissel.shopify-liquid"
    }
  }
}

Which will force this plugin to be the default formatter for HTML language files. Obviously that'll apply to filetypes other than .liquid, which isn't ideal but most likely fine for a Jekyll/Shopify project. Perhaps it could be built-in as an option, to this plugin? Might not be possible. Either way this issue could be closed and stay here to help anyone with the same problem.

PS: Fantastic plugin, thank you @panoply ! The "Generate a .liquidrc file" feature is genius.

entozoon avatar Sep 11 '19 15:09 entozoon

Thanks for this, it's much appreciated.

In next release (v2.4.0) you will be able to define formatting by file extension with HTML (.html) files needed to be included manually – this will help prevent these types of conflicts occurring. By default in v2.4.0 the following extensions will have formatting automatically applied.

Do you have any other suggestions or feature requests that might be helpful?

panoply avatar Sep 11 '19 15:09 panoply

That looks like a perfect solution, @panoply nice one! Only one possible feature request that comes to mind.. I'd like for it to convert {{foo.bar}} to {{ foo.bar }}, as is the recommended syntax. Perhaps {{ foo|asset_url }} to {{ foo | asset_url }} and that kind of thing. It'd be handy to fix all the crazy inconsistencies in peoples' code. Other than that, it's exactly what we need!

entozoon avatar Sep 11 '19 15:09 entozoon

Can you create another issue for this? @entozoon

panoply avatar Sep 11 '19 15:09 panoply

Is this still a workable solution? I can't figure out how to install the correct plugin to allow prettier to process my html files with liquid.

datapolitical avatar Dec 28 '21 22:12 datapolitical

🚢 Shipped v3.0.0

Take a look at the readme. You need to set the editor.defaultFormatter

panoply avatar Sep 28 '22 08:09 panoply