@mrhenry/stylelint-mrhenry-prop-order 3.0.14 → 3.0.16
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 +51 -38
- package/order.mjs +7 -0
- package/package.json +3 -3
package/index.mjs
CHANGED
|
@@ -5,8 +5,8 @@ const orderSet = new Set(order);
|
|
|
5
5
|
|
|
6
6
|
const ruleName = "@mrhenry/stylelint-mrhenry-prop-order";
|
|
7
7
|
const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
8
|
-
expected: (
|
|
9
|
-
return `Expected ${
|
|
8
|
+
expected: (names, orderedNames) => {
|
|
9
|
+
return `Expected ${names.join(', ')} to appear in ${orderedNames.join(', ')} order.`;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
|
|
@@ -20,8 +20,7 @@ const ignoredAtRules = [
|
|
|
20
20
|
'property'
|
|
21
21
|
];
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
23
|
+
const ruleFunction = (primaryOption) => {
|
|
25
24
|
return (postcssRoot, postcssResult) => {
|
|
26
25
|
const validPrimary = stylelint.utils.validateOptions(postcssResult, ruleName, {
|
|
27
26
|
actual: primaryOption,
|
|
@@ -63,6 +62,7 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
63
62
|
}
|
|
64
63
|
});
|
|
65
64
|
|
|
65
|
+
/** @type {Array<Array<import('postcss').Node>>} */
|
|
66
66
|
let declarationsSections = [[]];
|
|
67
67
|
container.each((node) => {
|
|
68
68
|
if (matchedComments.has(node)) {
|
|
@@ -99,47 +99,60 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
|
|
|
99
99
|
const firstNodeIndex = Math.min.apply(Math, section.map((x) => container.index(x)));
|
|
100
100
|
const originalFirstNode = container.nodes[firstNodeIndex];
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
const sectionPropNames = section.map((decl) => decl.prop);
|
|
103
|
+
const sortedSectionPropNames = sortedSection.map((decl) => decl.prop);
|
|
104
|
+
|
|
105
|
+
/** @type {import('postcss').Node} */
|
|
106
|
+
const firstDecl = section.at(0);
|
|
107
|
+
/** @type {import('postcss').Node} */
|
|
108
|
+
const lastDecl = section.at(-1);
|
|
109
|
+
|
|
110
|
+
const containerStartOffset = container.source?.start.offset;
|
|
111
|
+
const index = firstDecl.source?.start.offset - containerStartOffset;
|
|
112
|
+
const endIndex = lastDecl.source?.end.offset - containerStartOffset;
|
|
113
|
+
|
|
114
|
+
for (let i = 0; i < sectionPropNames.length; i++) {
|
|
115
|
+
const original = sectionPropNames[i];
|
|
116
|
+
const sorted = sortedSectionPropNames[i];
|
|
108
117
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
if (original === sorted) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
stylelint.utils.report({
|
|
123
|
+
message: messages.expected(sectionPropNames, sortedSectionPropNames),
|
|
124
|
+
node: container,
|
|
125
|
+
index,
|
|
126
|
+
endIndex,
|
|
127
|
+
result: postcssResult,
|
|
128
|
+
ruleName,
|
|
129
|
+
fix: () => {
|
|
130
|
+
sortedSection.reverse().forEach((decl) => {
|
|
131
|
+
container.insertBefore(firstNodeIndex, decl);
|
|
132
|
+
return;
|
|
117
133
|
});
|
|
134
|
+
|
|
135
|
+
const finalFirstNode = container.nodes[firstNodeIndex];
|
|
136
|
+
if (originalFirstNode.raws.before && finalFirstNode.raws.before) {
|
|
137
|
+
const originalRawBefore = originalFirstNode.raws.before;
|
|
138
|
+
originalFirstNode.raws.before = finalFirstNode.raws.before;
|
|
139
|
+
finalFirstNode.raws.before = originalRawBefore;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (const [comment, prev] of matchedComments) {
|
|
143
|
+
if (!section.includes(prev)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
comment.remove();
|
|
148
|
+
container.insertAfter(prev, comment);
|
|
149
|
+
}
|
|
118
150
|
}
|
|
119
151
|
});
|
|
120
|
-
}
|
|
121
152
|
|
|
122
|
-
|
|
123
|
-
sortedSection.reverse().forEach((decl) => {
|
|
124
|
-
container.insertBefore(firstNodeIndex, decl);
|
|
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;
|
|
133
|
-
}
|
|
153
|
+
break;
|
|
134
154
|
}
|
|
135
155
|
});
|
|
136
|
-
|
|
137
|
-
if (context.fix) {
|
|
138
|
-
for (const [comment, prev] of matchedComments) {
|
|
139
|
-
comment.remove();
|
|
140
|
-
container.insertAfter(prev, comment);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
156
|
});
|
|
144
157
|
};
|
|
145
158
|
};
|
package/order.mjs
CHANGED
|
@@ -34,6 +34,10 @@ export const order = [
|
|
|
34
34
|
"background-position-x",
|
|
35
35
|
"background-position-y",
|
|
36
36
|
"background-repeat",
|
|
37
|
+
"background-repeat-inline",
|
|
38
|
+
"background-repeat-block",
|
|
39
|
+
"background-repeat-x",
|
|
40
|
+
"background-repeat-y",
|
|
37
41
|
"background-size",
|
|
38
42
|
"baseline-source",
|
|
39
43
|
"block-step",
|
|
@@ -305,6 +309,7 @@ export const order = [
|
|
|
305
309
|
"lighting-color",
|
|
306
310
|
"line-break",
|
|
307
311
|
"line-clamp",
|
|
312
|
+
"line-fit-edge",
|
|
308
313
|
"line-grid",
|
|
309
314
|
"line-height",
|
|
310
315
|
"line-height-step",
|
|
@@ -533,6 +538,7 @@ export const order = [
|
|
|
533
538
|
"text-align-all",
|
|
534
539
|
"text-align-last",
|
|
535
540
|
"text-anchor",
|
|
541
|
+
"text-box",
|
|
536
542
|
"text-box-edge",
|
|
537
543
|
"text-box-trim",
|
|
538
544
|
"text-combine-upright",
|
|
@@ -594,6 +600,7 @@ export const order = [
|
|
|
594
600
|
"view-timeline-inset",
|
|
595
601
|
"view-timeline-name",
|
|
596
602
|
"view-transition-class",
|
|
603
|
+
"view-transition-group",
|
|
597
604
|
"view-transition-name",
|
|
598
605
|
"visibility",
|
|
599
606
|
"voice-balance",
|
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.16",
|
|
4
4
|
"description": "Mr. Henry's preferred order for CSS properties",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"stylelint-plugin"
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"stylelint": "^16.
|
|
30
|
+
"stylelint": "^16.8.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"css-tree": "^2.3.1",
|
|
34
|
-
"stylelint": "^16.
|
|
34
|
+
"stylelint": "^16.8.2"
|
|
35
35
|
}
|
|
36
36
|
}
|