@mrhenry/stylelint-mrhenry-prop-order 2.0.13 → 2.0.15

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": "@mrhenry/stylelint-mrhenry-prop-order",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "Mr. Henry's preferred order for CSS properties",
5
5
  "main": "stylelint-mrhenry-prop-order.cjs",
6
6
  "scripts": {
@@ -25,8 +25,16 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
25
25
  return;
26
26
  }
27
27
 
28
- postcssRoot.walkRules((rule) => {
29
- let parent = rule.parent;
28
+ postcssRoot.walk((container) => {
29
+ if (container.type !== 'atrule' && container.type !== 'rule') {
30
+ return;
31
+ }
32
+
33
+ if (!container.nodes?.length) {
34
+ return;
35
+ }
36
+
37
+ let parent = container;
30
38
  while (parent) {
31
39
  if (parent.type === 'atrule' && ignoredAtRules.includes(parent.name.toLowerCase())) {
32
40
  return;
@@ -36,14 +44,10 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
36
44
  }
37
45
 
38
46
  /* c8 ignore next */
39
- if (!rule.nodes.length) {
40
- return;
41
- }
42
-
43
47
  // Comments after a node, not one a new line should be kept together with that node.
44
48
  // color: red; /* my color */
45
49
  let matchedComments = new Map();
46
- rule.each((node) => {
50
+ container.each((node) => {
47
51
  if (node.type === 'comment' && !node.raws?.before?.match(/\n/g)) {
48
52
  const comment = node;
49
53
  const prev = comment.prev();
@@ -56,7 +60,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
56
60
  });
57
61
 
58
62
  let declarationsSections = [[]];
59
- rule.each((node) => {
63
+ container.each((node) => {
60
64
  if (
61
65
  node.type === 'decl' &&
62
66
  !node.variable &&
@@ -83,17 +87,17 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
83
87
  return order.indexOf(a.prop.toLowerCase()) - order.indexOf(b.prop.toLowerCase());
84
88
  });
85
89
 
86
- const firstNodeIndex = Math.min.apply(Math, section.map((x) => rule.index(x)));
87
- const originalFirstNode = rule.nodes[firstNodeIndex];
90
+ const firstNodeIndex = Math.min.apply(Math, section.map((x) => container.index(x)));
91
+ const originalFirstNode = container.nodes[firstNodeIndex];
88
92
 
89
93
  section.forEach((decl, index) => {
90
94
  const desiredIndex = firstNodeIndex + index;
91
- if (rule.index(decl) === desiredIndex) {
95
+ if (container.index(decl) === desiredIndex) {
92
96
  return;
93
97
  }
94
98
 
95
99
  if (context.fix) {
96
- rule.insertBefore(desiredIndex, decl);
100
+ container.insertBefore(desiredIndex, decl);
97
101
  return;
98
102
  }
99
103
 
@@ -109,7 +113,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
109
113
  }
110
114
  });
111
115
 
112
- const finalFirstNode = rule.nodes[firstNodeIndex];
116
+ const finalFirstNode = container.nodes[firstNodeIndex];
113
117
  if (originalFirstNode.raws.before && finalFirstNode.raws.before) {
114
118
  const originalRawBefore = originalFirstNode.raws.before;
115
119
  originalFirstNode.raws.before = finalFirstNode.raws.before;
@@ -119,7 +123,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
119
123
 
120
124
  if (context.fix) {
121
125
  for (const [comment, prev] of matchedComments) {
122
- rule.insertAfter(prev, comment);
126
+ container.insertAfter(prev, comment);
123
127
  }
124
128
  }
125
129
  });