@mrhenry/stylelint-mrhenry-prop-order 1.0.4 → 1.0.6
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 +1 -1
- package/order.js +2 -0
- package/package.json +4 -3
- package/stylelint-mrhenry-prop-order.js +40 -17
package/README.md
CHANGED
package/order.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrhenry/stylelint-mrhenry-prop-order",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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.
|
|
35
|
+
"@webref/css": "^6.3.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()
|
|
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
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
!
|
|
38
|
-
orderSet.has(
|
|
56
|
+
node.type === 'decl' &&
|
|
57
|
+
!node.variable &&
|
|
58
|
+
orderSet.has(node.prop.toLowerCase())
|
|
39
59
|
) {
|
|
40
|
-
if ((
|
|
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(
|
|
64
|
+
declarationsSections.at(-1).push(node);
|
|
45
65
|
|
|
46
|
-
|
|
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
|
};
|