-
-
Notifications
You must be signed in to change notification settings - Fork 485
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 #1285
Comments
I'm working on Comment Placement now |
….css as biome doesn't support it yet see biomejs/biome#1285
….css as biome doesn't support it yet see biomejs/biome#1285
….css as biome doesn't support it yet see biomejs/biome#1285
Is this the first step in implementing a CSS linter? Or could that be worked on in parallel? (the parser code seems pretty fleshed out already to my naked eye) |
The issue is only related to CSS formatting. I believe that the linter and formatter can work in parallel. Any help is welcome! |
Agreed, the parser is pretty far along, but there will be many changes before it can effectively lint full CSS files (for example, we're adding parsing for exact properties now, and each one will have a new node type, so writing lints for them now would require rewriting them entirely later on). |
….css as biome doesn't support it yet see biomejs/biome#1285
….css as biome doesn't support it yet see biomejs/biome#1285
I guess this is only about a pure CSS formatter, but what are your plans/thoughts about SCSS? |
It's unlikely that we'll add any non-standard CSS dialects in the short term. SCSS and other dialects like Less and even PostCSS end up diverging pretty far from standard CSS and require very different parsing to handle all of their extensions to the language syntax (e.g., mixins in sass and less, We may consider adding some support in the future, but for the forseeable future we will be focusing on supporting all of latest, standard CSS. |
BTW if sass is not supported why in documentation css super languages are mentioned? |
In my opinion, no amount of new CSS features will be enough to replace Sass completely. For me, Sass is more useful for having a modular code structure. It is like a missing piece between the CSS and the bundler. Although Tailwind and other no-CSS libraries are quite popular lately, I think Sass is still the best tool for anyone writing their own design system. But I understand it expands the scope a lot. So maybe it can be added as a plugin later (not sure if plugin system will support this), or it can have a minimal set of features (quotes, spacing, no prettier compatibility). |
Fully agree on this one, it could be a plugin or like jsonc options within the base language (in this case css) |
Just curious, what parts of Sass are you using, or what makes it the best for someone writing their own design system? |
The facts that Sass is adopting standard CSS nesting rules, and that functions/mixins are coming to CSS are good reasons enough to focus only on CSS. So because how everything is evolving, I think Biome should only focus on CSS. Then you have PostCSS to cover everything else. But I understand it's a matter of preferences at the end. |
It was mostly a scope decision. Writing a CSS recoverable parser isn't an easy task, so we wanted to be realistic and start small. We will consider SASS down the line once our base CSS parser is more stable. |
can we add support for emotion or styled component? |
@conioX that's called embedded formatting, which is tracked in a separate issue |
Where is it being tracked? |
A quick issue search finds #3334. |
I saw that recently biome added support for |
@ashishsurya No, CSS is supported, SCSS isn't. |
Is that on the way or still in the Roadmap? @matthiask |
@ashishsurya It's not on the roadmap yet. We would consider it once CSS parser is stable enough. |
Would love that, don't see scss usage lowering any time soon. |
SCSS usage is already lowering right now. Looking at the last 5 years of usage, it reached its peak in 2017 and usage remained plateaued until early 2023. It's been declining ever since. Most of SCSS's features are already widely supported in CSS. Some have been subsumed by newer more powerful CSS features. The majority of new projects don't need to reach for SCSS any more, and legacy projects are migrating away from it to speed up build times. The last niche advantages of SCSS appear to be conditionals, loops, and mixins. But all 3 of them have current workarounds today and active css extension proposals getting worked out with current and future concerns in mind. Those that would be working on adding new major features to SCSS are focussing instead on adding those features to CSS instead. |
No it's not As @KurtGokhan mentioned;
For big organisations working with design systems it's still a good choice as a tool between CSS & the bundler. e.g. Maps, sets, functions, mixins, looping. And yes CSS is slowly catching up, but I doubt it will replace sass within the upcoming 2 years. |
It actually is. Long winded explanation in this expanding sectionYou've made a few statistics mistakes.
Conclusion: SCSS usage is falling.
What if the features you use overlap? What would be the purpose of using Sass at that point?
Sass and modular code are unrelated to each other. You can have non-modular sass, modular sass, non-modular css, and modular css. You just use your filesystem and your import method of choice. (e.g. Sass'
Well my dinner's ready now so I'll have to rush past the rest of this. Most designs systems written a few years ago used scss because its maps/sets/functions/mixins/loops were the best way to do what we wanted, which was making certain tasks easily and programmatically tweakable. For example:
But now, we have better ways:
There's a lot more I could write about not needing to design things using techniques built on assumptions that no longer hold true, but I'm getting quite hungry now. |
New to this thread but just wanted to express interest in scss support for a different reason: legacy projects. "One toolchain for your web project" hopefully doesn't have to mean "One toolchain for your new web project". I'm not a frontend dev, I do mostly backend and devops, but I often help other teams with tooling, configuration, and standardization. So far I love biome for new projects, but it's not a drop in replacement for existing tooling and configuration in every existing project yet. I'd love to bring biome into every project, new and old. I think plugins would be a fine solution as well, once we have them. Anyway I appreciate all the work being done on biome and the care being put into making it great. Thank you! |
👏🏻👏🏻👏🏻 |
SCSS support will be greatly appreciated |
@spartanatreyu Although some of your points are very valid, the question is not if css can do everything that sass can do, but if it should all the time. I like to keep heavy fluid calculations and other stuff abstracted away in the build/on the server with easy to use helpers, and use new css features only where it makes sense to use them. Why should i deliver hundreds of extra kilobytes to the browser/user, when i don't have to. Sure css is not as ressource intensive as js, but it still uses resources. And the last design system i saw, which solely relied on css vars, had 300kb of core css vars and their semantic remapping, this is insane. It depends on the use case at the end. Just wanted to point out, there are more reasons (and performance for example, is a big one), why you'd want to use sass as an extension to css. |
@jens-struct focussing on CSS is almost never where we should be focussing our attention when it comes to peering through the lens of performance improvements since there's usually something else having a greater impact.
I'm guessing just by you mentioning When it comes to 300kb of custom properties, there's a few possibilities that come to my mind. It's either:
If your hesitation is instead towards having custom properties instead of scss variables because they're precomputed, it's worth pointing out: Since Custom Properties are computed at runtime, they're not beholden to the requirements of static analysis. This means they can be granted greater power than SCSS variables could ever be granted (e.g. cascading, types, and all that follows from them) and you're trading that precompute for that extra power. But if your hesitation is instead towards having custom properties instead of scss variables because they result in more calculations, it's worth pointing out: Custom properties can often describe things in a more performant way than the equivalent SCSS. For example: CSS would use |
@spartanatreyu thanks for your answer.
Oh, this is simply not true, in most cases. First, if you take performance seriously it is not only about optimizing the things that have the greatest impact, but things that have an impact in comparison to effort and improvement potential. Secondly, depending on your frontend architecture, CSS can be the single blocking ressource for the critical rendering path, which makes it normally a quite important ressource to optimize.
Not at all, i'm talking about a recent example i came across about a common architectural design token pattern (in the context of design systems), where you have core design tokens, like a complete color palette. And then remap some of these core design tokens (which are not meant to be ever used directly) to semantic design tokens (which are meant to be used directly). Doing this kind of stuff in the browser has no value to the user or the functionality of the frontend. It is just bloating the delivered CSS. But this is just one example. And it's ok, there is no wrong way here, as nobody knows all the reasons, why someone in a specific project, with specific constraints and specific goals, has very valid reasons to use Sass as an extension to CSS for some things. Don't get me wrong, CSS vars are great. You can even generate CSS vars with sass. It is not about one or the other, but choosing the right tool for a specific problem, depending on the context. If you ask me, Sass will probably never be obsolete, but i don't care if you decide not to use it anymore. Lets leave this choice to the biome users, if it at some points supports Sass. Although i guess your intention was to help and educate, at first. |
Description
This issue will act as the hub for tracking the CSS formatter as it gets built out. Listed here are all of the different pieces that will need to be implemented to get "complete" support in place. For the most part, this means compatibility with Prettier, and the implementations will inevitably take on the same shape, but we are not currently aiming for perfect parity with Pretttier, as their implementation and tests lean heavily into PostCSS and other facets that we are not yet ready to support.
How to Contribute
Everyone is welcome to contribute pieces here! If you'd like to tackle something, please leave a comment below this issue for which item(s) of the checklist below you'd like to pick up. We will create a separate issue and assign it to you to simplify tracking.
Note
In order to have the issue assigned to you, you must comment on this issue.
When choosing an item to work on, there are often various pieces that will fit together or be dependent on each other, like
attribute_selector
requiresattribute_name
,attribute_matcher
, andattribute_matcher_value
to be implemented at the same time to get full support.Also, please only pick a single piece or group to work on at a time, and try to have time available to work on the piece when you select it so that we can keep progressing quickly. If you need any help or have any questions about how to implement formatting in Biome, feel free to ask in the
dev-formatter
channel in Discord.Testing
We don't currently have Prettier tests for the CSS formatter, again because much of Prettier's implementation focuses on supporting PostCSS, beyond just standard CSS that Biome supports currently. Instead, please add spec tests under
crates/biome_css_formatter/test/specs/css
for the feature you are working on. For the most part, Prettier's CSS tests do provide a lot of coverage and examples to pull from.Node Checklist
The CSS Parser is still in progress, so the set of nodes that need to be formatted is constantly changing. All of the current nodes have been implemented, but as new ones are added, they will need to be formatted as well. Since it's moving so quickly, the list won't be updated here. Instead, there are a number of other general things that need support, listed below.
Once the parser reaches a mostly complete and stable state, we will flesh out the list of remaining types that need formatting support and add them here.
Features and bug fixes
These are features, bug fixes, and other adjustments that need to be made to the formatter to get closer to parity with Prettier.
[type=text]
becomes[type="text"]
) (feat(css_formatter): Always quote attribute matcher values #1321)5PX
become5px
, at-rules like@MEDIA
become@media
, types likeDIV
becomediv
, etc.) (feat(css_formatter): automatically downcase all keywords and regular identifiers #1354)Formatting Infrastructure
Listed here are various things that are ready to be implemented or fixed that apply to the CSS formatter in general.
quoteStyle
for css formatting #1384)biome ignore: format
suppression comments in appropriate placesTesting:
Releasability
These tasks need to be completed for the CSS formatter to be "publicly available" and on-par with the JS formatter.
can_format_css_yet
flag frombiome_service
.The text was updated successfully, but these errors were encountered: