@mrhenry/stylelint-mrhenry-prop-order 3.0.11 → 3.0.12
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/index.mjs +37 -29
- package/package.json +2 -2
package/index.mjs
CHANGED
|
@@ -49,8 +49,7 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
49
49
|
parent = parent.parent;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
// Comments after a node, not one a new line should be kept together with that node.
|
|
52
|
+
// Comments after a node, not on a new line should be kept together with that node.
|
|
54
53
|
// color: red; /* my color */
|
|
55
54
|
let matchedComments = new Map();
|
|
56
55
|
container.each((node) => {
|
|
@@ -60,13 +59,16 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
60
59
|
|
|
61
60
|
if (prev) {
|
|
62
61
|
matchedComments.set(comment, prev);
|
|
63
|
-
comment.remove();
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
});
|
|
67
65
|
|
|
68
66
|
let declarationsSections = [[]];
|
|
69
67
|
container.each((node) => {
|
|
68
|
+
if (matchedComments.has(node)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
70
72
|
if (
|
|
71
73
|
node.type === 'decl' &&
|
|
72
74
|
!node.variable &&
|
|
@@ -89,46 +91,52 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
89
91
|
});
|
|
90
92
|
|
|
91
93
|
declarationsSections.forEach((section) => {
|
|
92
|
-
|
|
94
|
+
const sortedSection = [...section];
|
|
95
|
+
sortedSection.sort((a, b) => {
|
|
93
96
|
return order.indexOf(a.prop.toLowerCase()) - order.indexOf(b.prop.toLowerCase());
|
|
94
97
|
});
|
|
95
98
|
|
|
96
99
|
const firstNodeIndex = Math.min.apply(Math, section.map((x) => container.index(x)));
|
|
97
100
|
const originalFirstNode = container.nodes[firstNodeIndex];
|
|
98
101
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
if (!context.fix) {
|
|
103
|
+
sortedSection.forEach((decl, index) => {
|
|
104
|
+
const oldIndex = section.indexOf(decl);
|
|
105
|
+
if (index === oldIndex) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (index < section.length - 1) {
|
|
110
|
+
stylelint.utils.report({
|
|
111
|
+
message: messages.expected(decl.prop),
|
|
112
|
+
node: decl,
|
|
113
|
+
index: 0,
|
|
114
|
+
endIndex: decl.prop.length,
|
|
115
|
+
result: postcssResult,
|
|
116
|
+
ruleName,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
104
121
|
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
if (context.fix) {
|
|
123
|
+
sortedSection.reverse().forEach((decl) => {
|
|
124
|
+
container.insertBefore(firstNodeIndex, decl);
|
|
107
125
|
return;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const finalFirstNode = container.nodes[firstNodeIndex];
|
|
129
|
+
if (originalFirstNode.raws.before && finalFirstNode.raws.before) {
|
|
130
|
+
const originalRawBefore = originalFirstNode.raws.before;
|
|
131
|
+
originalFirstNode.raws.before = finalFirstNode.raws.before;
|
|
132
|
+
finalFirstNode.raws.before = originalRawBefore;
|
|
108
133
|
}
|
|
109
|
-
|
|
110
|
-
if (index < section.length - 1) {
|
|
111
|
-
stylelint.utils.report({
|
|
112
|
-
message: messages.expected(decl.prop),
|
|
113
|
-
node: decl,
|
|
114
|
-
index: 0,
|
|
115
|
-
endIndex: decl.prop.length,
|
|
116
|
-
result: postcssResult,
|
|
117
|
-
ruleName,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const finalFirstNode = container.nodes[firstNodeIndex];
|
|
123
|
-
if (originalFirstNode.raws.before && finalFirstNode.raws.before) {
|
|
124
|
-
const originalRawBefore = originalFirstNode.raws.before;
|
|
125
|
-
originalFirstNode.raws.before = finalFirstNode.raws.before;
|
|
126
|
-
finalFirstNode.raws.before = originalRawBefore;
|
|
127
134
|
}
|
|
128
135
|
});
|
|
129
136
|
|
|
130
137
|
if (context.fix) {
|
|
131
138
|
for (const [comment, prev] of matchedComments) {
|
|
139
|
+
comment.remove();
|
|
132
140
|
container.insertAfter(prev, comment);
|
|
133
141
|
}
|
|
134
142
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrhenry/stylelint-mrhenry-prop-order",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.12",
|
|
4
4
|
"description": "Mr. Henry's preferred order for CSS properties",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"stylelint": "^16.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"stylelint": "^16.
|
|
33
|
+
"stylelint": "^16.7.0"
|
|
34
34
|
}
|
|
35
35
|
}
|