stylelint-plugin-logical-css 0.7.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -42,30 +42,44 @@ configuration.
|
|
|
42
42
|
|
|
43
43
|
## Rules
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
- [plugin/use-logical-properties-and-values](#pluginuse-logical-properties-and-values)
|
|
46
|
+
- [plugin/use-logical-units](#pluginuse-logical-units)
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
---
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
👈**
|
|
50
|
+
### plugin/use-logical-properties-and-values
|
|
51
51
|
|
|
52
52
|
This rule is responsible for checking both CSS properties and values. When a
|
|
53
53
|
physical property or value is found, it will be flagged.
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"rules": {
|
|
58
|
+
"plugin/use-logical-properties-and-values": [
|
|
59
|
+
true,
|
|
60
|
+
{ "severity": "warning" }
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
#### Options
|
|
58
67
|
|
|
59
|
-
| Option
|
|
60
|
-
|
|
|
61
|
-
|
|
|
68
|
+
| Option | Description |
|
|
69
|
+
| ---------------- | ------------------------------------------------------------------------ |
|
|
70
|
+
| disable-auto-fix | Use this option to prevent auto-fixing warnings and errors while saving. |
|
|
71
|
+
| ignore | Pass an array of physical properties to ignore while linting. |
|
|
62
72
|
|
|
63
73
|
```json
|
|
64
74
|
{
|
|
65
75
|
"rules": {
|
|
66
76
|
"plugin/use-logical-properties-and-values": [
|
|
67
77
|
true,
|
|
68
|
-
{
|
|
78
|
+
{
|
|
79
|
+
"severity": "warning",
|
|
80
|
+
"disable-auto-fix": true,
|
|
81
|
+
"ignore": ["overflow-y", "overflow-x"]
|
|
82
|
+
}
|
|
69
83
|
]
|
|
70
84
|
}
|
|
71
85
|
}
|
|
@@ -91,11 +105,120 @@ The use-logical-properties-and-values rule accepts the following options:
|
|
|
91
105
|
}
|
|
92
106
|
```
|
|
93
107
|
|
|
94
|
-
|
|
108
|
+
#### Supported Properties and Values
|
|
109
|
+
|
|
110
|
+
##### Properties for sizing
|
|
111
|
+
|
|
112
|
+
| Physical Property | Logical Property |
|
|
113
|
+
| ----------------- | ----------------- |
|
|
114
|
+
| `height` | `block-size` |
|
|
115
|
+
| `width` | `inline-size` |
|
|
116
|
+
| `max-height` | `max-block-size` |
|
|
117
|
+
| `max-width` | `max-inline-size` |
|
|
118
|
+
| `min-height` | `min-block-size` |
|
|
119
|
+
| `min-width` | `min-inline-size` |
|
|
120
|
+
|
|
121
|
+
##### Properties for margins, borders, and padding
|
|
122
|
+
|
|
123
|
+
| Physical Property | Logical Property |
|
|
124
|
+
| ------------------------------------------ | --------------------------- |
|
|
125
|
+
| `border-top` & `border-bottom` | `border-block` |
|
|
126
|
+
| `border-top-color` & `border-bottom-color` | `border-block-color` |
|
|
127
|
+
| `border-top-style` & `border-bottom-style` | `border-block-style` |
|
|
128
|
+
| `border-top-width` & `border-bottom-width` | `border-block-width` |
|
|
129
|
+
| `border-left` & `border-right` | `border-inline` |
|
|
130
|
+
| `border-left-color` & `border-right-color` | `border-inline-color` |
|
|
131
|
+
| `border-left-style` & `border-right-style` | `border-inline-style` |
|
|
132
|
+
| `border-left-width` & `border-right-width` | `border-inline-width` |
|
|
133
|
+
| `border-bottom` | `border-block-end` |
|
|
134
|
+
| `border-bottom-color` | `border-block-end-color` |
|
|
135
|
+
| `border-bottom-style` | `border-block-end-style` |
|
|
136
|
+
| `border-bottom-width` | `border-block-end-width` |
|
|
137
|
+
| `border-top` | `border-block-start` |
|
|
138
|
+
| `border-top-color` | `border-block-start-color` |
|
|
139
|
+
| `border-top-style` | `border-block-start-style` |
|
|
140
|
+
| `border-top-width` | `border-block-start-width` |
|
|
141
|
+
| `border-right` | `border-inline-end` |
|
|
142
|
+
| `border-right-color` | `border-inline-end-color` |
|
|
143
|
+
| `border-right-style` | `border-inline-end-style` |
|
|
144
|
+
| `border-right-width` | `border-inline-end-width` |
|
|
145
|
+
| `border-left` | `border-inline-start` |
|
|
146
|
+
| `border-left-color` | `border-inline-start-color` |
|
|
147
|
+
| `border-left-style` | `border-inline-start-style` |
|
|
148
|
+
| `border-left-width` | `border-inline-start-width` |
|
|
149
|
+
| `border-bottom-left-radius` | `border-end-start-radius` |
|
|
150
|
+
| `border-bottom-right-radius` | `border-end-end-radius` |
|
|
151
|
+
| `border-top-left-radius` | `border-start-start-radius` |
|
|
152
|
+
| `border-top-right-radius` | `border-start-end-radius` |
|
|
153
|
+
| `margin-top` & `margin-bottom` | `margin-block` |
|
|
154
|
+
| `margin-top` | `margin-block-start` |
|
|
155
|
+
| `margin-bottom` | `margin-block-end` |
|
|
156
|
+
| `margin-left` & `margin-right` | `margin-inline` |
|
|
157
|
+
| `margin-left` | `margin-inline-start` |
|
|
158
|
+
| `margin-right` | `margin-inline-end` |
|
|
159
|
+
| `padding-top` & `padding-bottom` | `padding-block` |
|
|
160
|
+
| `padding-top` | `padding-block-start` |
|
|
161
|
+
| `padding-bottom` | `padding-block-end` |
|
|
162
|
+
| `padding-left` & `padding-right` | `padding-inline` |
|
|
163
|
+
| `padding-left` | `padding-inline-start` |
|
|
164
|
+
| `padding-right` | `padding-inline-end` |
|
|
165
|
+
|
|
166
|
+
##### Properties for floating and positioning
|
|
167
|
+
|
|
168
|
+
| Physical Property | Logical Property |
|
|
169
|
+
| ----------------- | --------------------- |
|
|
170
|
+
| `clear: left` | `clear: inline-start` |
|
|
171
|
+
| `clear: right` | `clear: inline-end` |
|
|
172
|
+
| `float: left` | `float: inline-start` |
|
|
173
|
+
| `float: right` | `float: inline-end` |
|
|
174
|
+
| `top` & `bottom` | `inset-block` |
|
|
175
|
+
| `top` | `inset-block-start` |
|
|
176
|
+
| `bottom` | `inset-block-end` |
|
|
177
|
+
| `left` & `right` | `inset-inline` |
|
|
178
|
+
| `left` | `inset-inline-start` |
|
|
179
|
+
| `right` | `inset-inline-end` |
|
|
180
|
+
|
|
181
|
+
##### Properties for size containment
|
|
182
|
+
|
|
183
|
+
| Physical Property | Logical Property |
|
|
184
|
+
| -------------------------- | ------------------------------- |
|
|
185
|
+
| `contain-intrinsic-height` | `contain-intrinsic-block-size` |
|
|
186
|
+
| `contain-intrinsic-width` | `contain-intrinsic-inline-size` |
|
|
187
|
+
|
|
188
|
+
##### Other properties
|
|
189
|
+
|
|
190
|
+
| Physical Property | Logical Property |
|
|
191
|
+
| ---------------------------------------------- | ----------------------------------- |
|
|
192
|
+
| `(-webkit-)box-orient: vertical` | `(-webkit-)box-orient: block-axis` |
|
|
193
|
+
| `(-webkit-)box-orient: horizontal` | `(-webkit-)box-orient: inline-axis` |
|
|
194
|
+
| `caption-size: top` | `caption-side: block-start` |
|
|
195
|
+
| `caption-size: bottom` | `caption-side: block-end` |
|
|
196
|
+
| `caption-size: right` | `caption-side: inline-end` |
|
|
197
|
+
| `caption-size: left` | `caption-side: inline-start` |
|
|
198
|
+
| `overflow-y` | `overflow-block` |
|
|
199
|
+
| `overflow-x` | `overflow-inline` |
|
|
200
|
+
| `overscroll-behavior-x` | `overscroll-behavior-inline` |
|
|
201
|
+
| `overscroll-behavior-y` | `overscroll-behavior-block` |
|
|
202
|
+
| `resize: horizontal` | `resize: inline` |
|
|
203
|
+
| `resize: vertical` | `resize: block` |
|
|
204
|
+
| 'scroll-margin-bottom` | `scroll-margin-block-end` |
|
|
205
|
+
| 'scroll-margin-bottom` & 'scroll-margin-top` | `scroll-margin-block` |
|
|
206
|
+
| 'scroll-margin-left` | `scroll-margin-inline-start` |
|
|
207
|
+
| 'scroll-margin-left` & 'scroll-margin-right` | `scroll-margin-inline` |
|
|
208
|
+
| 'scroll-margin-right` | `scroll-margin-inline-end` |
|
|
209
|
+
| 'scroll-margin-top` | `scroll-margin-block-start` |
|
|
210
|
+
| 'scroll-padding-bottom` | `scroll-padding-block-end` |
|
|
211
|
+
| 'scroll-padding-bottom` & 'scroll-padding-top` | `scroll-padding-block` |
|
|
212
|
+
| 'scroll-padding-left` | `scroll-padding-inline-start` |
|
|
213
|
+
| 'scroll-padding-left` & 'scroll-padding-right` | `scroll-padding-inline` |
|
|
214
|
+
| 'scroll-padding-right` | `scroll-padding-inline-end` |
|
|
215
|
+
| 'scroll-padding-top` | `scroll-padding-block-start` |
|
|
216
|
+
| `text-align: left` | `text-align: start` |
|
|
217
|
+
| `text-align: right` | `text-align: end` |
|
|
95
218
|
|
|
96
|
-
|
|
219
|
+
---
|
|
97
220
|
|
|
98
|
-
|
|
221
|
+
### plugin/use-logical-units
|
|
99
222
|
|
|
100
223
|
This rule is responsible for checking that logical CSS units are used.
|
|
101
224
|
Specifically, viewport units like `vw` and `vh` which stand for viewport width
|
|
@@ -103,20 +226,31 @@ and viewport height respectively will not reflect different writing modes and
|
|
|
103
226
|
directions. Instead, this rule will enforce the logical equivalents, `vi` and
|
|
104
227
|
`vb`.
|
|
105
228
|
|
|
106
|
-
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"rules": {
|
|
232
|
+
"plugin/use-logical-units": [true, { "severity": "warning" }]
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
107
236
|
|
|
108
|
-
|
|
237
|
+
#### Options
|
|
109
238
|
|
|
110
|
-
| Option
|
|
111
|
-
|
|
|
112
|
-
|
|
|
239
|
+
| Option | Description |
|
|
240
|
+
| ---------------- | ------------------------------------------------------------------------ |
|
|
241
|
+
| disable-auto-fix | Use this option to prevent auto-fixing warnings and errors while saving. |
|
|
242
|
+
| ignore | Pass an array of physical units to ignore while linting. |
|
|
113
243
|
|
|
114
244
|
```json
|
|
115
245
|
{
|
|
116
246
|
"rules": {
|
|
117
|
-
"plugin/use-logical-
|
|
247
|
+
"plugin/use-logical-properties-and-values": [
|
|
118
248
|
true,
|
|
119
|
-
{
|
|
249
|
+
{
|
|
250
|
+
"severity": "warning",
|
|
251
|
+
"disable-auto-fix": true,
|
|
252
|
+
"ignore": ["dvh", "dvw"]
|
|
253
|
+
}
|
|
120
254
|
]
|
|
121
255
|
}
|
|
122
256
|
}
|
|
@@ -140,8 +274,18 @@ body {
|
|
|
140
274
|
}
|
|
141
275
|
```
|
|
142
276
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
277
|
+
#### Supported Units
|
|
278
|
+
|
|
279
|
+
> Read about current
|
|
280
|
+
> [browser support for logical viewport units](https://caniuse.com/mdn-css_types_length_viewport_percentage_units_dynamic).
|
|
281
|
+
|
|
282
|
+
| Physical Unit | Logical Unit |
|
|
283
|
+
| ------------- | ------------- |
|
|
284
|
+
| dvh | dvb |
|
|
285
|
+
| dvw | dvi |
|
|
286
|
+
| lvh | lvb |
|
|
287
|
+
| lvw | lvi |
|
|
288
|
+
| svh | svb |
|
|
289
|
+
| svw | svi |
|
|
290
|
+
| vh | vb |
|
|
291
|
+
| vw | vi |
|
package/package.json
CHANGED
|
@@ -20,7 +20,10 @@ const ruleFunction = (_, options, context) => {
|
|
|
20
20
|
|
|
21
21
|
root.walkDecls((decl) => {
|
|
22
22
|
let rootProp = decl.prop;
|
|
23
|
-
if (
|
|
23
|
+
if (
|
|
24
|
+
Array.isArray(options?.ignore) &&
|
|
25
|
+
options?.ignore.includes(rootProp)
|
|
26
|
+
) {
|
|
24
27
|
return;
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -47,7 +50,7 @@ const ruleFunction = (_, options, context) => {
|
|
|
47
50
|
physicalValuesMap[rootProp][decl.value],
|
|
48
51
|
);
|
|
49
52
|
|
|
50
|
-
if (context.fix && options?.['
|
|
53
|
+
if (context.fix && !options?.['disable-auto-fix']) {
|
|
51
54
|
if (propIsPhysical) {
|
|
52
55
|
decl.prop = physicalPropertiesMap[rootProp];
|
|
53
56
|
}
|
|
@@ -20,12 +20,20 @@ const ruleFunction = (_, options, context) => {
|
|
|
20
20
|
if (!unitIsPhysical) return;
|
|
21
21
|
|
|
22
22
|
const physicalUnit = getValueUnit(decl.value);
|
|
23
|
+
|
|
24
|
+
if (
|
|
25
|
+
Array.isArray(options?.ignore) &&
|
|
26
|
+
options?.ignore.includes(physicalUnit)
|
|
27
|
+
) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
const message = ruleMessages.unexpectedUnit(
|
|
24
32
|
physicalUnit,
|
|
25
33
|
physicalUnitsMap[physicalUnit],
|
|
26
34
|
);
|
|
27
35
|
|
|
28
|
-
if (context.fix && options?.['
|
|
36
|
+
if (context.fix && !options?.['disable-auto-fix']) {
|
|
29
37
|
decl.value = decl.value.replace(
|
|
30
38
|
physicalUnit,
|
|
31
39
|
physicalUnitsMap[physicalUnit],
|
package/src/utils/logical.js
CHANGED
|
@@ -71,6 +71,18 @@ const logicalProperties = Object.freeze({
|
|
|
71
71
|
paddingInline: 'padding-inline',
|
|
72
72
|
paddingInlineEnd: 'padding-inline-end',
|
|
73
73
|
paddingInlineStart: 'padding-inline-start',
|
|
74
|
+
scrollMarginBlock: 'scroll-margin-block',
|
|
75
|
+
scrollMarginBlockEnd: 'scroll-margin-block-end',
|
|
76
|
+
scrollMarginBlockStart: 'scroll-margin-block-start',
|
|
77
|
+
scrollMarginInline: 'scroll-margin-inline',
|
|
78
|
+
scrollMarginInlineEnd: 'scroll-margin-inline-end',
|
|
79
|
+
scrollMarginInlineStart: 'scroll-margin-inline-start',
|
|
80
|
+
scrollPaddingBlock: 'scroll-padding-block',
|
|
81
|
+
scrollPaddingBlockEnd: 'scroll-padding-block-end',
|
|
82
|
+
scrollPaddingBlockStart: 'scroll-padding-block-start',
|
|
83
|
+
scrollPaddingInline: 'scroll-padding-inline',
|
|
84
|
+
scrollPaddingInlineEnd: 'scroll-padding-inline-end',
|
|
85
|
+
scrollPaddingInlineStart: 'scroll-padding-inline-start',
|
|
74
86
|
});
|
|
75
87
|
|
|
76
88
|
const logicalUnits = Object.freeze({
|
package/src/utils/physical.js
CHANGED
|
@@ -53,6 +53,14 @@ const physicalProperties = Object.freeze({
|
|
|
53
53
|
paddingTop: 'padding-top',
|
|
54
54
|
resize: 'resize',
|
|
55
55
|
right: 'right',
|
|
56
|
+
scrollMarginBottom: 'scroll-margin-bottom',
|
|
57
|
+
scrollMarginLeft: 'scroll-margin-left',
|
|
58
|
+
scrollMarginRight: 'scroll-margin-right',
|
|
59
|
+
scrollMarginTop: 'scroll-margin-top',
|
|
60
|
+
scrollPaddingBottom: 'scroll-padding-bottom',
|
|
61
|
+
scrollPaddingLeft: 'scroll-padding-left',
|
|
62
|
+
scrollPaddingRight: 'scroll-padding-right',
|
|
63
|
+
scrollPaddingTop: 'scroll-padding-top',
|
|
56
64
|
textAlign: 'text-align',
|
|
57
65
|
top: 'top',
|
|
58
66
|
width: 'width',
|
|
@@ -54,6 +54,22 @@ const physicalPropertiesMap = Object.freeze({
|
|
|
54
54
|
[physicalProperties.paddingLeft]: logicalProperties.paddingInlineStart,
|
|
55
55
|
[physicalProperties.paddingRight]: logicalProperties.paddingInlineEnd,
|
|
56
56
|
[physicalProperties.paddingTop]: logicalProperties.paddingBlockStart,
|
|
57
|
+
[physicalProperties.scrollMarginBottom]:
|
|
58
|
+
logicalProperties.scrollMarginBlockEnd,
|
|
59
|
+
[physicalProperties.scrollMarginLeft]:
|
|
60
|
+
logicalProperties.scrollMarginInlineStart,
|
|
61
|
+
[physicalProperties.scrollMarginRight]:
|
|
62
|
+
logicalProperties.scrollMarginInlineEnd,
|
|
63
|
+
[physicalProperties.scrollMarginTop]:
|
|
64
|
+
logicalProperties.scrollMarginBlockStart,
|
|
65
|
+
[physicalProperties.scrollPaddingBottom]:
|
|
66
|
+
logicalProperties.scrollPaddingBlockEnd,
|
|
67
|
+
[physicalProperties.scrollPaddingLeft]:
|
|
68
|
+
logicalProperties.scrollPaddingInlineStart,
|
|
69
|
+
[physicalProperties.scrollPaddingRight]:
|
|
70
|
+
logicalProperties.scrollPaddingInlineEnd,
|
|
71
|
+
[physicalProperties.scrollPaddingTop]:
|
|
72
|
+
logicalProperties.scrollPaddingBlockStart,
|
|
57
73
|
[physicalProperties.right]: logicalProperties.insetInlineEnd,
|
|
58
74
|
[physicalProperties.top]: logicalProperties.insetBlockStart,
|
|
59
75
|
[physicalProperties.width]: logicalProperties.inlineSize,
|