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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-plugin-logical-css",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A Stylelint plugin to enforce the use of logical CSS properties, values and units.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -19,22 +19,24 @@ const ruleFunction = (_, options, context) => {
19
19
 
20
20
  const physicalUnit = getValueUnit(decl.value);
21
21
 
22
- if (
23
- Array.isArray(options?.ignore) &&
24
- options?.ignore.includes(physicalUnit)
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[physicalUnit],
33
+ physicalUnit.map((unit) => physicalUnitsMap[unit]),
32
34
  );
33
35
 
34
36
  if (context.fix) {
35
- decl.value = decl.value.replace(
36
- physicalUnit,
37
- physicalUnitsMap[physicalUnit],
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 = /(\d+\s?)(cqh|cqw|dvh|dvw|lvh|lvw|svh|svw|vh|vw|)(\s+|$)/;
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 matchedUnit = match.find((item) =>
11
- Object.values(physicalUnits).includes(item),
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 unit = getValueUnit(value);
20
+ const units = getValueUnit(value);
19
21
 
20
- if (!unit) return false;
22
+ if (!units) return false;
21
23
 
22
- const unitIsPhysical = Object.values(physicalUnits).includes(unit);
24
+ const unitIsPhysical = Object.values(physicalUnits).some((unit) =>
25
+ units.find((match) => match.includes(unit)),
26
+ );
23
27
 
24
28
  return unitIsPhysical;
25
29
  }