-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
CSS formatter problem when using tailwindcss #2012
Comments
To be clear the spaces in https://tailwindcss.com/docs/editor-setup#syntax-support points out that the custom at-rules can confuse editors and formatters. This would be an example of that. If you want to do there work, including providing tests I'd be happy to review well-tested PRs. |
Related microsoft/vscode#147548 . @DibyodyutiMondal |
This might be done by adding and at-rule here: Or there might be some simpler way. |
Sure, I'll see what I can do and revert back. This will definitely take some time, though, because I have never used beautify before, so I'll have to learn. |
@bitwiseman The problem also occurs on modifiers here, let's take the example above :
As you can see, the first This leads to an error when compiling. Do you have any idea on correcting this ? Do I need to create a new issue for this ? |
Any news on this? This also happens on Windows and for example with |
wow, still not fixed. I'm coming from IntelliJ to VSCode and this is quite funny that formatting your code breaks your CSS all the time |
@mklueh |
I found out where it was problematic : js/src/css/beautifier.js line 375
It considers the |
microsoft/vscode-css-languageservice#333 (comment)
h3 {
@apply hover:text-red-400
} after formatting : h3 {
@apply hover: text-red-400
} To be frank this is not an issue with this package/project. This is a Tailwind issue. Tailwind invented a syntax where whitespace is important, this clashes with the core of CSS where whitespace is discarded. Tailwind should take ownership of the fallout it causes and roll it's own tooling (language support, formatters, linters, ...). These two are exact equals for any spec compliant CSS tokenizer/parser :
|
@romainmenke Is this behaviour working fine with a line like this ? :
the result is this ?
It should probably behave the same way and this is not a Tailwind syntax here. I am not sure though. |
But those are also exact equivalents for any spec compliant CSS tokenizer/parser. When people invent non-CSS-like syntax it will cause issues in various tools. Tools might choose to support everything and that is awesome, but I don't think we can classify this case as a bug or an issue in this package. |
I saw days ago that there's already a behavior on @extend and @import in the css-beautify source code. But you're right. |
Yes, don't get me wrong, if people want to spend time to support things like this, then that is awesome. But I think it is important to keep framing this as "non-standard" and "made up". (everything is made up, but I think you get what I mean :)) The added maintenance cost is much larger for things like these than it would be for regular CSS. |
@romainmenke @itemshopp I would still say there is a bug in this project for this input:
The output is:
The first @itemshopp Now that you have an examples the reproduces the bug, would you be willing to try your PR again? |
@bitwiseman, let's try this out. I'll add a new test in the css/tests.js file :
And find out if it results in any error by launching EDIT: It seems to be working, I'll PR it again and check if everything is ok. |
@floroz It isn't yet approved by VSCode. We will have to wait this PR to be merged : microsoft/vscode-css-languageservice#354 (review). |
Got it! Thanks for your work guys :) |
Hi,
Description
The CSS formatter inserts unnecessary spaces when using tailwindcss, causing errors when building.
An example is below.
Input
The code looked like this before beautification:
Actual Output
The code actually looked like this after beautification:
Steps to Reproduce
Environment
OS: Windows
Settings
VSCode Buildin Formatter Default
Is there a setting to work around this?
Tailwindcss is indispensable and it would be great if you could fix it.
Thanks.
The text was updated successfully, but these errors were encountered: