Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
laszlo1337 opened this issue Oct 15, 2023 · 1 comment
Closed

Comments

@laszlo1337
Copy link

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

@laszlo1337 laszlo1337 changed the title Prettier breaks file when wrapping text in curly braces [WebStorm] Prettier breaks file when wrapping variables in curly braces [WebStorm] Oct 15, 2023
@dummdidumm
Copy link
Member

Closing as duplicate of #233 and #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.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants