stylelint-plugin-logical-css 0.10.0 → 0.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-plugin-logical-css",
3
- "version": "0.10.0",
3
+ "version": "0.11.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
  "files": [
@@ -38,16 +38,25 @@ const ruleFunction = (_, options, context) => {
38
38
  if (!isValidProp) return;
39
39
 
40
40
  const isTransitionProperty = rootProp === 'transition';
41
- const physicalTransitionValue =
41
+ const physicalTransitionProperties =
42
42
  isTransitionProperty &&
43
- Object.values(physicalProperties).find((property) =>
44
- decl.value.includes(property) ? property : null,
45
- );
43
+ Object.values(physicalProperties)
44
+ .flatMap((property) => {
45
+ const exp = new RegExp(`(^|[^\\w-])${property}([^\\w-]|$)`);
46
+ return decl.value.match(exp);
47
+ })
48
+ .filter((p) => p && p.trim());
49
+
46
50
  const propIsPhysical = isPhysicalProperty(decl.prop);
47
51
  const valueIsPhysical = isPhysicalValue(decl.value);
48
52
 
49
- if (!propIsPhysical && !valueIsPhysical && !physicalTransitionValue)
53
+ if (
54
+ !propIsPhysical &&
55
+ !valueIsPhysical &&
56
+ !physicalTransitionProperties.length
57
+ ) {
50
58
  return;
59
+ }
51
60
 
52
61
  let message;
53
62
 
@@ -64,11 +73,11 @@ const ruleFunction = (_, options, context) => {
64
73
  physicalValuesMap[rootProp][decl.value],
65
74
  );
66
75
  }
67
-
68
- if (physicalTransitionValue) {
76
+ if (physicalTransitionProperties.length) {
77
+ const propertyToFlag = physicalTransitionProperties[0].trim();
69
78
  message = ruleMessages.unexpectedTransitionValue(
70
- physicalTransitionValue,
71
- physicalPropertiesMap[physicalTransitionValue],
79
+ propertyToFlag,
80
+ physicalPropertiesMap[propertyToFlag],
72
81
  );
73
82
  }
74
83
 
@@ -81,11 +90,16 @@ const ruleFunction = (_, options, context) => {
81
90
  decl.value = physicalValuesMap[rootProp][decl.value];
82
91
  }
83
92
 
84
- if (physicalTransitionValue) {
85
- decl.value = decl.value.replace(
86
- physicalTransitionValue,
87
- physicalPropertiesMap[physicalTransitionValue],
88
- );
93
+ if (physicalTransitionProperties.length) {
94
+ let newValue = decl.value;
95
+ physicalTransitionProperties.forEach((property) => {
96
+ newValue = newValue.replace(
97
+ property.trim(),
98
+ physicalPropertiesMap[property.trim()],
99
+ );
100
+ });
101
+
102
+ decl.value = newValue;
89
103
  }
90
104
 
91
105
  return;