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

format *.vue style like unocss/tailwindcss hover:bg-red-400 got blank space #1448

Closed
JiatLn opened this issue Jun 13, 2022 · 23 comments
Closed
Labels

Comments

@JiatLn
Copy link

JiatLn commented Jun 13, 2022

GIF 2022-6-13 15-21-52

"[vue]": {
    "editor.defaultFormatter": "Vue.volar"
  },
<style scoped lang="scss">
h3 {
  @apply hover:text-red-400 // <- when save file it change to hover: text-red-400
}
</style>
@johnsoncodehk
Copy link
Member

This is https://github.com/microsoft/vscode-css-languageservice behavior we can't fix, but you can change css formatter to prettier by https://github.com/johnsoncodehk/volar-plugins/tree/master/packages/prettier.

@wlkns
Copy link

wlkns commented Jul 13, 2022

I'm also facing this issue, is there a configuration option or way to use prettier globally versus within a single project?

@leosin
Copy link

leosin commented Aug 9, 2022

same +1

how to use prettier only format css code in .vue file?

or can i use stylelint to fix?

i don't like prettier plug to format vue template..

@jamiecarter7
Copy link

+1

1 similar comment
@pgrazek
Copy link

pgrazek commented Aug 12, 2022

+1

@Boris-Karamanolev
Copy link

Any fix?

@johnsoncodehk
Copy link
Member

@wlkns You can feature request for it.

@leosin You can make you own stylelint plugin by volar langauge service plugin API. And you can push it to https://github.com/johnsoncodehk/volar-plugins if you want.

@Boris-Karamanolev
Copy link

Is there any workaround at the moment? This is really breaking development.

@acidjazz
Copy link

i tried the volar plugin - didnt work - this did ->

  1. Install the Prettier formatter
  2. Add this to your User settings JSON
    "[css]": {
        "editor.formatOnSave": true,
        "diffEditor.codeLens": true,
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    }

To get to this settings file:

  1. open your command palette with cmd+p or ctrl+p
  2. type > and look for Open User Settings (JSON)

To make sure this is working:

  1. type > again in your command palette
  2. search for Developer: Reload Window

@kknono
Copy link

kknono commented Oct 18, 2022

i tried the volar plugin - didnt work - this did ->

  1. Install the Prettier formatter
  2. Add this to your User settings JSON
    "[css]": {
        "editor.formatOnSave": true,
        "diffEditor.codeLens": true,
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    }

To get to this settings file:

  1. open your command palette with cmd+p or ctrl+p
  2. type > and look for Open User Settings (JSON)

To make sure this is working:

  1. type > again in your command palette
  2. search for Developer: Reload Window

"CSS › Format: Enable"
disabled

@tve
Copy link

tve commented Dec 28, 2022

I don't find that

    "[css]": {
        ...
    }

works 'cause it only applies to .css files. Like the OP I need it to apply to the CSS in .vue files. Switching .vue files to use prettier as the default formatter works but I really don't like how it formats templates...

@xinlangzi
Copy link

Anyone has solution to avoid the auto space inside the .vue file?

@focussing
Copy link

Is there any workaround at the moment? This is really breaking development.

@wlkns
Copy link

wlkns commented Feb 9, 2023

The solution is to install prettier within the project itself with the tailwind prettier plugin. This seems to have worked for me.

@focussing
Copy link

focussing commented Feb 9, 2023

@wlkns thanks, if I understand you correctly that would be another workaround, no solution. Vetur didn't have this issue so in this case Volar is one step back.
Either implement a working built-in formatter or leave it out completley.

@johnsoncodehk
Copy link
Member

Either implement a working built-in formatter or leave it out completley.

The results here are consistent with formatting .scss in VSCode, I suggest you open an issue with https://github.com/microsoft/vscode-css-languageservice.

@focussing
Copy link

focussing commented Feb 28, 2023 via email

@WilliamYi74
Copy link

same +1 inside .vue style, have any solution?

@Gal94
Copy link

Gal94 commented Jul 9, 2023

It seems to have been fixed in the upstream, could this issue get looked into?
@johnsoncodehk

@so1ve
Copy link
Member

so1ve commented Jul 9, 2023

My suggestion is not to use Volar's built-in formatter. You can install the prettier extension in vscode and set editor.defaultFormatter to it.

@focussing
Copy link

I checked with VSCODE version 1.80.0 (june 2023) and Volar extension version 1.8.4 (5 days ago) and the issue is NOT FIXED

@so1ve
Copy link
Member

so1ve commented Jul 10, 2023

@focussing This bug hasn't been fixed in vscode yet (they didn't update the dependencies and create a new release). Once this issue is resolve in upstream, we can upgrade dependencies to fix this problem.

@focussing
Copy link

@so1ve I used your suggestion to use Prettier because it takes too long to have it done right in Volar/Code.
It works superb, thank you!
Hopefully they decide to eiter fix it or to leave it out completely or "do nothing".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests