-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Use prettier-plugin-tailwindcss to format css classes #1376
Comments
I guess there also should be an opt-in setting for this since some tailwind users probably don't want the formatting. |
Relevant:
That's what I did and now |
Closing this. As pointed out in the comment above, Tailwind bundles this Svelte plugin, so use the Tailwind plugin instead. Tell VS Code to format Svelte files with the Prettier extension (install it if you haven't), and then npm install the Tailwind plugin into your node_modules instead of the Svelte plugin. |
For anyone stumbling upon this, here is what I had to do to make it work (using pnpm but not sure if relevant).
{
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
}
{
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.documentSelectors": ["**/*.svelte"]
} |
not working for me :/ |
It worked but I had to reload window. |
You might want to try disabling the pluginSearchDirs and specifying both plugins manually, with tailwind coming last: |
Only adding the vscode settings should solve the issue. No need to remove the Here is my {
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 80,
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
"pluginSearchDirs": false,
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
} Here are my full vscode settings under {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.documentSelectors": ["**/*.svelte"],
"eslint.validate": ["javascript", "typescript", "svelte"],
"files.associations": {
"*.css": "tailwindcss"
},
"editor.quickSuggestions": {
"strings": true
}
} |
I guess I must be missing something rather obvious, but I'm following the docs and I can get ti to work I created this question at SO with the detailed steps, but basically I cannot get prettier to format svelte files, I get a an "Extension 'Prettier - Code Formatter' is configured as formatter but it cannot format 'Svelte' files` error And If I use the I created this repo for testing, you can open it with gitpod, just open and if you run I had to add "prettier.documentSelectors": ["**/*.svelte"] to ny vscode settings file. I explained the issue here this is how vscode settings ended up: {
"prettier.documentSelectors": ["**/*.svelte"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"svelte.enable-ts-plugin": true
} and my {
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
"pluginSearchDirs": false,
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
} |
This is closed but figured I would share what ended up working for me. The svelte plugin was seemingly working and the tailwindcss plugin was also working on .html files, but not on .svelte files. I was able to finally get the classes to sort with the setup below and testing using the In
In
For
I have the Prettier and the Svelte for VS Code extensions installed. |
So I have a working version of this by adding
prettier-plugin-tailwindcss
as a dep to thesvelte-vscode
package and then looking for atailwind.config.js
file in the VSCode workspace when formatting a svelte file to selectively use either theprettier-plugin-tailwindcss
orprettier-plugin-svelte
to format. I am not sure what the desired solution is by the community/maintainers. But I can submit a PR if this sounds like what people want.The text was updated successfully, but these errors were encountered: