sveltejs / prettier-plugin-svelte

Format your svelte components using prettier.
MIT License
735 stars 95 forks source link

Prettier breaks file when wrapping variables in curly braces [WebStorm] #405

Closed laszlo1337 closed 8 months ago

laszlo1337 commented 11 months ago

Prettier 3.0.3

In WebStorm, when editing .svelte files, when trying to wrap text in {} by selecting the text and pressing shift + { prettier breaks completely. Steps:

  1. Create example component image

  2. Select text that needs to be wrapped in {} image

  3. Press Shift + { and experience the file getting screwed image

This does not happen in .js files, and wrapping in square brackets works as intended (Shift + [)

prettierrc file

{
  "useTabs": true,
  "singleQuote": true,
  "trailingComma": "all",
  "printWidth": 180,
  "semi": false,
  "plugins": [
    "prettier-plugin-svelte"
  ],
  "pluginSearchDirs": [
    "."
  ],
  "overrides": [
    {
      "files": "*.svelte",
      "options": {
        "parser": "svelte"
      }
    }
  ]
}

This happens also when committing with "Reformat code" and "Optimize imports" checkboxes checked. The code was committed in a broken state.

Expected behavior: Should format the component without breaking

dummdidumm commented 8 months ago

Closing as duplicate of https://github.com/sveltejs/prettier-plugin-svelte/issues/233 and https://github.com/sveltejs/prettier-plugin-svelte/issues/242 TLDR: prettier does not support plugin like prettier-plugin-svelte to partake in the "format range" option properly, and so when your editor does auto-format on code action, it will likely invoke prettier with the range option, resulting in the given gibberish.