useSortedProperties
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
assist/source/useSortedProperties¥Diagnostic Category:
assist/source/useSortedProperties
如何在编辑器中启用
Section titled “如何在编辑器中启用”¥How to enable in your editor
{ "editor.codeActionsOnSave": { "source.action.useSortedProperties.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.useSortedProperties.biome": true, "source.fixAll.biome": true }}source.action.useSortedProperties.biome ¥How to configure
{ "assist": { "actions": { "source": { "useSortedProperties": "on" } } }}¥Description
强制要求 CSS 属性和嵌套规则的顺序。
¥Enforce ordering of CSS properties and nested rules.
此规则确保 CSS 规则的内容顺序一致。
¥This rule ensures the contents of a CSS rule are ordered consistently.
属性按语义排序,更重要的属性位于顶部附近,相似的属性分组在一起。嵌套规则和 at 规则位于属性之后。
¥Properties are ordered semantically, with more important properties near the top and similar properties grouped together. Nested rules and at-rules are placed after properties.
顺序大致如下:
¥The ordering is roughly:
-
自定义属性
¥Custom properties
-
布局属性(display、flex、grid)
¥Layout properties (display, flex, grid)
-
边距和内边距属性
¥Margin and padding properties
-
排版属性(字体、颜色)
¥Typography properties (font, color)
-
交互属性(指针事件、可见性)
¥Interaction properties (pointer-events, visibility)
-
背景和边框属性
¥Background and border properties
-
过渡和动画属性
¥Transition and animation properties
-
嵌套规则、媒体查询和其他 at 规则
¥Nested rules, media queries and other at-rules
¥Examples
¥Invalid
p { transition: opacity 1s ease; border: 1px solid black; pointer-events: none; color: black; margin: 8px; display: block; --custom: 100;}code-block.css:1:3 assist/source/useSortedProperties FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The properties are not sorted.
> 1 │ p {
│ ^
> 2 │ transition: opacity 1s ease;
> 3 │ border: 1px solid black;
> 4 │ pointer-events: none;
> 5 │ color: black;
> 6 │ margin: 8px;
> 7 │ display: block;
> 8 │ —custom: 100;
> 9 │ }
│ ^
10 │
ℹ Safe fix: Sort these properties
1 1 │ p {
2 │ - ··transition:·opacity·1s·ease;
3 │ - ··border:·1px·solid·black;
4 │ - ··pointer-events:·none;
2 │ + ··--custom:·100;
3 │ + ··display:·block;
4 │ + ··margin:·8px;
5 5 │ color: black;
6 │ - ··margin:·8px;
7 │ - ··display:·block;
8 │ - ··--custom:·100;
6 │ + ··pointer-events:·none;
7 │ + ··border:·1px·solid·black;
8 │ + ··transition:·opacity·1s·ease;
9 9 │ }
10 10 │
p { span { color: blue; } color: red;}code-block.css:1:3 assist/source/useSortedProperties FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The properties are not sorted.
> 1 │ p {
│ ^
> 2 │ span { color: blue; }
> 3 │ color: red;
> 4 │ }
│ ^
5 │
ℹ Safe fix: Sort these properties
1 1 │ p {
2 │ - ··span·{·color:·blue;·}
3 │ - ··color:·red;
2 │ + ··color:·red;
3 │ + ··span·{·color:·blue;·}
4 4 │ }
5 5 │
¥Valid
p { --custom: 100; display: block; margin: 8px; color: black; pointer-events: none; border: 1px solid black; transition: opacity 1s ease;}p { color: red; span { color: blue; }}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号