stylelint-plugin-logical-css 1.0.0 → 1.1.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 +4 -0
- package/package.json +1 -1
- package/src/rules/use-logical-units/index.js +10 -8
- package/src/utils/isPhysicalUnit.js +10 -6
package/README.md
CHANGED
|
@@ -270,6 +270,10 @@ directions. Instead, this rule will enforce the logical equivalents, `vi` and
|
|
|
270
270
|
body {
|
|
271
271
|
max-block-size: 100vh; /* Will flag the physical use of viewport "height" */
|
|
272
272
|
}
|
|
273
|
+
|
|
274
|
+
.container {
|
|
275
|
+
inline-size: clamp(10vw, 100%, 50vw); /* Will flag the physical use of viewport "width" */
|
|
276
|
+
}
|
|
273
277
|
```
|
|
274
278
|
|
|
275
279
|
##### Allowed
|
package/package.json
CHANGED
|
@@ -19,22 +19,24 @@ const ruleFunction = (_, options, context) => {
|
|
|
19
19
|
|
|
20
20
|
const physicalUnit = getValueUnit(decl.value);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
22
|
+
const ignore = physicalUnit.some(
|
|
23
|
+
(unit) =>
|
|
24
|
+
Array.isArray(options?.ignore) && options?.ignore.includes(unit),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (ignore) {
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const message = ruleMessages.unexpectedUnit(
|
|
30
32
|
physicalUnit,
|
|
31
|
-
physicalUnitsMap[
|
|
33
|
+
physicalUnit.map((unit) => physicalUnitsMap[unit]),
|
|
32
34
|
);
|
|
33
35
|
|
|
34
36
|
if (context.fix) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
physicalUnit.forEach(
|
|
38
|
+
(unit) =>
|
|
39
|
+
(decl.value = decl.value.replace(unit, physicalUnitsMap[unit])),
|
|
38
40
|
);
|
|
39
41
|
|
|
40
42
|
return;
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import { physicalUnits } from './physical.js';
|
|
2
2
|
|
|
3
|
-
const expression =
|
|
3
|
+
const expression = /\b\d+(\.\d+)?\s*(cqh|cqw|dvh|dvw|lvh|lvw|svh|svw|vh|vw)\b/g;
|
|
4
4
|
|
|
5
5
|
export function getValueUnit(value) {
|
|
6
6
|
const match = value.match(expression);
|
|
7
7
|
|
|
8
8
|
if (!match) return false;
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const matches = Array.isArray(match) ? match : [match];
|
|
11
|
+
|
|
12
|
+
const matchedUnit = matches.map(
|
|
13
|
+
(match) => physicalUnits[match.replace(/[0-9]/g, '')],
|
|
12
14
|
);
|
|
13
15
|
|
|
14
16
|
return matchedUnit;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export function isPhysicalUnit(value) {
|
|
18
|
-
const
|
|
20
|
+
const units = getValueUnit(value);
|
|
19
21
|
|
|
20
|
-
if (!
|
|
22
|
+
if (!units) return false;
|
|
21
23
|
|
|
22
|
-
const unitIsPhysical = Object.values(physicalUnits).
|
|
24
|
+
const unitIsPhysical = Object.values(physicalUnits).some((unit) =>
|
|
25
|
+
units.find((match) => match.includes(unit)),
|
|
26
|
+
);
|
|
23
27
|
|
|
24
28
|
return unitIsPhysical;
|
|
25
29
|
}
|