Closed opensas closed 12 months ago
just did a couple more test, and I think I found the issue
I needed to add "files.associations": {"*.svelte": "html" }
to my settings file, I guess that with that configuration vscode prettier extensions knows it can format svelte files
I'll do a couple more tests anyway
my current ./.vscode/settings.json
{
"files.autoSave": "onFocusChange",
"files.associations": { "*.svelte": "html" },
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.configPath": ".prettierrc",
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
}
The "files.associations": { "*.svelte": "html" },
brought other troubles, basically since svelte files are treated as HTML typescript syntax is not allowed.
So I had to add this instead "prettier.documentSelectors": ["**/*.svelte"],
The reason for this option is explained here
Since we are we are overriding svelte files from the .prietterrc
file (with { files: ['*.svelte'], options: { parser: 'svelte' } }
) we also need to let the prettier vscode extension know that it can handle svelte files.
Also found this comment with the same solution
perhaps we could add a mention in the docs about this setting, it was particular hard to find
edit: just submitted this PR
I configure my project following these instructions
But vscode cannot use
esbenp.prettier-vscode
to format Svelte files, I get the following error:from the command line
pnpm format
works as expectedSteps to reproduce:
.prettierrc file
.vscode/settings.json
fileinstalled extensions
package.json