sveltejs / prettier-plugin-svelte

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

vscode prettier doesn't seem to use the plugin, even when .prettierrc configured #401

Open mikemaccana opened 10 months ago

mikemaccana commented 10 months ago

Per the instructions I've created a config file:

{
  "plugins": ["prettier-plugin-svelte"]
}

And when I save the file and format with the Prettier extension:

Prettier - Code formatter
v10.1.0
Prettier
prettier.io

It uses the config file:

["INFO" - 12:09:26] Using config file at '/Users/mikemaccana/Code/mycompany/myapp/.prettierrc'

But no changes occur to my svelte files.

Command line works fine:

npx prettier --write --plugin prettier-plugin-svelte .

(I can see the files are now neatened)

potatotomatobanana commented 9 months ago

Use .prettierrc.js file name, it may fix the issue.

NOTE: Use string values for plugins same as:

{
  "plugins": ["prettier-plugin-svelte"]
}
Loizzus commented 9 months ago

I have a similar issue where it seems the settings in my .prettierrc file are not being applied. These are my settings:

{
    "plugins": ["prettier-plugin-svelte"],
    "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],  
    "bracketSameLine": true,
    "htmlWhitespaceSensitivity": "ignore",
    "useTabs": true,
    "singleQuote": true,
    "semi": false,
    "trailingComma": "none",
    "printWidth": 160
}

And in my VS Code settings.json I added these lines:

  "[javascript][html][typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
  },
  "[svelte]": {
    "editor.defaultFormatter": "svelte.svelte-vscode",
  },

Changes are being applied to my svelte files but code in a +page.svelte file that I am happy being formatted like this:

<div class="result-stats">
    <span>Displaying <b>{arrRangeStart + 1}-{arrRangeStart + displayedUsers}</b> of <b>{teamMembers.length}</b> team members</span>
</div>

is being formatted to this:

<div class="result-stats">
    <span
        >Displaying <b>{arrRangeStart + 1}-{arrRangeStart + displayedUsers}</b> of
        <b>{teamMembers.length}</b> team members</span
    >
</div>

The config file is in the root of my project directory so I don't see what the issue could be. image

DePasqualeOrg commented 7 months ago

Use .prettierrc.js file name, it may fix the issue.

I tried this, and it works for a little while, but then the plugin stops working, and I have to change the name back to get it to work again, until it stops working and I have to change it back ... ad infinitum.

TonyLeCode commented 7 months ago

Yea, the plugin randomly stops working for me. Changing path to something invalid back to .prettierrc seems to be a temporary solution.

DePasqualeOrg commented 7 months ago

It seems that the issue may be due to problems with prettier-vscode.

asjir commented 3 months ago

Here's what has worked for me:

Ad I installed prettier and prettier-plugin-svelte in project root.

Further observations to hopefully help find the issue

In particular "editor.defaultFormatter": "svelte.svelte-vscode", I didn't manage to get to use my config. Also I never managed to get prettier to work consistently without setting --config explicitly. Running prettier with --find-config-path never found the path - renaming ".prettierrc.yaml" to ".prettierrc" didn't help.

This considered the only fix svelte team can apply I suppose is adding support for specifying prettier config path.