sveltejs / prettier-plugin-svelte

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

Wired formats with `svelteIndentScriptAndStyle` option in WebStorm #375

Closed RoyRao2333 closed 1 year ago

RoyRao2333 commented 1 year ago

Here's my .prettierrc.json:

{
  "trailingComma": "all",
  "tabWidth": 2,
  "printWidth": 80,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "quoteProps": "as-needed",
  "bracketSpacing": true,
  "arrowParens": "always",
  "endOfLine": "lf",
  "svelteSortOrder": "options-styles-scripts-markup",
  "svelteStrictMode": true,
  "svelteBracketNewLine": false,
  "svelteAllowShorthand": false,
  "svelteIndentScriptAndStyle": false,
  "tailwindConfig": "./tailwind.config.js",
  "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
  "overrides": [
    {
      "files": "*.svelte",
      "options": {
        "parser": "svelte"
      }
    }
  ]
}

Before formatting:

image

After formatting:

image

You can notice that codes in <script> tag lost indents. <button>'s props is also formatted wrong.

But if I remove "svelteIndentScriptAndStyle": false and format:

image

Seems alright but I think the trailing > of <button> is supposed to be in a new line...

I'm new to Svelte and really love this framework. I came from React and I just copy & paste the .prettierrc from my previous React project and made some changes. Don't know if I set something wrong, any help would be appreciated!

dummdidumm commented 1 year ago

This works as expected:

Hope this clears things up - welcome to Svelte!

RoyRao2333 commented 1 year ago

@dummdidumm

Thanks for the explanations! Really helpful. :)

But as I described above, can I make the trailing > of <button> in a new line like this?

image

I think this can separate component's attributes from the children (or slot?) within it and it's easy to read.

dummdidumm commented 1 year ago

For that, remove "svelteBracketNewLine": false, from your config

RoyRao2333 commented 1 year ago

@dummdidumm

It's working and thanks for the help! You truly saved my day!