@mrhenry/stylelint-mrhenry-prop-order 1.0.3 → 1.0.5

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
@@ -5,7 +5,7 @@
5
5
  Mr. Henry's preferred order for CSS properties.
6
6
 
7
7
  This package does not group properties.
8
- It only sorts them within a "imaginary sections".
8
+ It only sorts them within "imaginary sections".
9
9
 
10
10
  Acts as a separator between sections :
11
11
  - ignored declarations
package/order.js CHANGED
@@ -289,6 +289,7 @@ module.exports = [
289
289
  "line-height-step",
290
290
  "line-padding",
291
291
  "line-snap",
292
+ "link-parameters",
292
293
  "list-style",
293
294
  "list-style-image",
294
295
  "list-style-position",
@@ -300,11 +301,11 @@ module.exports = [
300
301
  "margin-block",
301
302
  "margin-block-start",
302
303
  "margin-block-end",
303
- "margin-break",
304
304
  "margin-top",
305
305
  "margin-right",
306
306
  "margin-bottom",
307
307
  "margin-left",
308
+ "margin-break",
308
309
  "margin-trim",
309
310
  "marker",
310
311
  "marker-start",
@@ -363,6 +364,16 @@ module.exports = [
363
364
  "overflow-inline",
364
365
  "overflow-block",
365
366
  "overflow-clip-margin",
367
+ "overflow-clip-margin-inline",
368
+ "overflow-clip-margin-inline-start",
369
+ "overflow-clip-margin-inline-end",
370
+ "overflow-clip-margin-block",
371
+ "overflow-clip-margin-block-start",
372
+ "overflow-clip-margin-block-end",
373
+ "overflow-clip-margin-top",
374
+ "overflow-clip-margin-right",
375
+ "overflow-clip-margin-bottom",
376
+ "overflow-clip-margin-left",
366
377
  "overflow-wrap",
367
378
  "overscroll-behavior",
368
379
  "overscroll-behavior-x",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrhenry/stylelint-mrhenry-prop-order",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Mr. Henry's preferred order for CSS properties",
5
5
  "main": "stylelint-mrhenry-prop-order.js",
6
6
  "scripts": {
@@ -18,7 +18,8 @@
18
18
  "files": [
19
19
  "order.js",
20
20
  "stylelint-mrhenry-prop-order.js",
21
- "LICENSE"
21
+ "LICENSE",
22
+ "README.md"
22
23
  ],
23
24
  "jest": {
24
25
  "preset": "jest-preset-stylelint"
@@ -31,7 +32,7 @@
31
32
  "stylelint": "^14.16.1"
32
33
  },
33
34
  "devDependencies": {
34
- "@webref/css": "^6.1.1",
35
+ "@webref/css": "^6.2.0",
35
36
  "c8": "^7.12.0",
36
37
  "jest": "^29.3.1",
37
38
  "jest-preset-stylelint": "^6.0.0",
@@ -13,16 +13,21 @@ const meta = {
13
13
  url: "https://github.com/mrhenry/stylelint-mrhenry-prop-order"
14
14
  };
15
15
 
16
+ const ignoredAtRules = [
17
+ 'font-face',
18
+ 'property'
19
+ ];
20
+
16
21
  const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
17
22
  return (postcssRoot, postcssResult) => {
18
23
  postcssRoot.walkRules((rule) => {
19
24
  let parent = rule.parent;
20
25
  while (parent) {
21
- if (parent.type === 'atrule' && parent.name.toLowerCase() === 'font-face') {
26
+ if (parent.type === 'atrule' && ignoredAtRules.includes(parent.name.toLowerCase())) {
22
27
  return;
23
28
  }
24
29
 
25
- parent = parent.parent
30
+ parent = parent.parent;
26
31
  }
27
32
 
28
33
  if (!rule.nodes.length) {
@@ -30,28 +35,43 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
30
35
  return;
31
36
  }
32
37
 
33
- let declarationsSections = [[]]
34
- for (let i = 0; i < rule.nodes.length; i++) {
38
+ // Comments after a node, not one a new line should be kept together with that node.
39
+ // color: red; /* my color */
40
+ let matchedComments = new Map();
41
+ rule.each((node) => {
42
+ if (node.type === 'comment' && !node.raws?.before?.match(/\n/g)) {
43
+ const comment = node;
44
+ const prev = comment.prev();
45
+
46
+ if (prev) {
47
+ matchedComments.set(comment, prev);
48
+ comment.remove();
49
+ }
50
+ }
51
+ });
52
+
53
+ let declarationsSections = [[]];
54
+ rule.each((node) => {
35
55
  if (
36
- rule.nodes[i].type === 'decl' &&
37
- !rule.nodes[i].variable &&
38
- orderSet.has(rule.nodes[i].prop.toLowerCase())
56
+ node.type === 'decl' &&
57
+ !node.variable &&
58
+ orderSet.has(node.prop.toLowerCase())
39
59
  ) {
40
- if ((rule.nodes[i].raws?.before?.match(/\n/g) || []).length >= 2) {
41
- declarationsSections.push([])
60
+ if ((node.raws?.before?.match(/\n/g) || []).length >= 2) {
61
+ declarationsSections.push([]);
42
62
  }
43
63
 
44
- declarationsSections.at(-1).push(rule.nodes[i]);
64
+ declarationsSections.at(-1).push(node);
45
65
 
46
- continue;
66
+ return;
47
67
  }
48
68
 
49
- declarationsSections.push([])
50
- }
69
+ declarationsSections.push([]);
70
+ });
51
71
 
52
72
  declarationsSections = declarationsSections.filter((x) => {
53
- return x.length > 1
54
- })
73
+ return x.length > 1;
74
+ });
55
75
 
56
76
  declarationsSections.forEach((section) => {
57
77
  section.sort((a, b) => {
@@ -68,8 +88,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
68
88
  }
69
89
 
70
90
  if (context.fix) {
71
- rule.insertBefore(desiredIndex, decl)
72
-
91
+ rule.insertBefore(desiredIndex, decl);
73
92
  return;
74
93
  }
75
94
 
@@ -92,6 +111,10 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
92
111
  finalFirstNode.raws.before = originalRawBefore;
93
112
  }
94
113
  });
114
+
115
+ for (const [comment, prev] of matchedComments) {
116
+ rule.insertAfter(prev, comment);
117
+ }
95
118
  });
96
119
  };
97
120
  };