@mrhenry/stylelint-mrhenry-prop-order 3.0.13 → 3.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.
Files changed (3) hide show
  1. package/index.mjs +50 -36
  2. package/order.mjs +16 -14
  3. package/package.json +4 -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: (name) => {
9
- return `Expected ${name} to appear at a different position.`;
8
+ expected: (names, orderedNames) => {
9
+ return `Expected ${names.join(', ')} to appear in ${orderedNames.join(', ')} order.`;
10
10
  }
11
11
  });
12
12
 
@@ -63,6 +63,7 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
63
63
  }
64
64
  });
65
65
 
66
+ /** @type {Array<Array<import('postcss').Node>>} */
66
67
  let declarationsSections = [[]];
67
68
  container.each((node) => {
68
69
  if (matchedComments.has(node)) {
@@ -99,47 +100,60 @@ const ruleFunction = (primaryOption, secondaryOption, context) => {
99
100
  const firstNodeIndex = Math.min.apply(Math, section.map((x) => container.index(x)));
100
101
  const originalFirstNode = container.nodes[firstNodeIndex];
101
102
 
102
- if (!context.fix) {
103
- sortedSection.forEach((decl, index) => {
104
- const oldIndex = section.indexOf(decl);
105
- if (index === oldIndex) {
106
- return;
107
- }
103
+ const sectionPropNames = section.map((decl) => decl.prop);
104
+ const sortedSectionPropNames = sortedSection.map((decl) => decl.prop);
105
+
106
+ /** @type {import('postcss').Node} */
107
+ const firstDecl = section.at(0);
108
+ /** @type {import('postcss').Node} */
109
+ const lastDecl = section.at(-1);
110
+
111
+ const containerStartOffset = container.source?.start.offset;
112
+ const index = firstDecl.source?.start.offset - containerStartOffset;
113
+ const endIndex = lastDecl.source?.end.offset - containerStartOffset;
114
+
115
+ for (let i = 0; i < sectionPropNames.length; i++) {
116
+ const original = sectionPropNames[i];
117
+ const sorted = sortedSectionPropNames[i];
108
118
 
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,
119
+ if (original === sorted) {
120
+ continue;
121
+ }
122
+
123
+ stylelint.utils.report({
124
+ message: messages.expected(sectionPropNames, sortedSectionPropNames),
125
+ node: container,
126
+ index,
127
+ endIndex,
128
+ result: postcssResult,
129
+ ruleName,
130
+ fix: () => {
131
+ sortedSection.reverse().forEach((decl) => {
132
+ container.insertBefore(firstNodeIndex, decl);
133
+ return;
117
134
  });
135
+
136
+ const finalFirstNode = container.nodes[firstNodeIndex];
137
+ if (originalFirstNode.raws.before && finalFirstNode.raws.before) {
138
+ const originalRawBefore = originalFirstNode.raws.before;
139
+ originalFirstNode.raws.before = finalFirstNode.raws.before;
140
+ finalFirstNode.raws.before = originalRawBefore;
141
+ }
142
+
143
+ for (const [comment, prev] of matchedComments) {
144
+ if (!section.includes(prev)) {
145
+ continue;
146
+ }
147
+
148
+ comment.remove();
149
+ container.insertAfter(prev, comment);
150
+ }
118
151
  }
119
152
  });
120
- }
121
153
 
122
- if (context.fix) {
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
- }
154
+ break;
134
155
  }
135
156
  });
136
-
137
- if (context.fix) {
138
- for (const [comment, prev] of matchedComments) {
139
- comment.remove();
140
- container.insertAfter(prev, comment);
141
- }
142
- }
143
157
  });
144
158
  };
145
159
  };
package/order.mjs CHANGED
@@ -1,9 +1,5 @@
1
1
  export const order = [
2
2
  "accent-color",
3
- "align-content",
4
- "align-items",
5
- "align-self",
6
- "alignment-baseline",
7
3
  "all",
8
4
  "anchor-name",
9
5
  "anchor-scope",
@@ -39,9 +35,7 @@ export const order = [
39
35
  "background-position-y",
40
36
  "background-repeat",
41
37
  "background-size",
42
- "baseline-shift",
43
38
  "baseline-source",
44
- "block-ellipsis",
45
39
  "block-step",
46
40
  "block-step-align",
47
41
  "block-step-insert",
@@ -120,7 +114,10 @@ export const order = [
120
114
  "border-bottom-right-radius",
121
115
  "border-boundary",
122
116
  "border-limit",
117
+
118
+ "corners",
123
119
  "border-radius",
120
+
124
121
  "border-spacing",
125
122
  "border-clip",
126
123
  "border-clip-top",
@@ -163,16 +160,15 @@ export const order = [
163
160
  "color-interpolation",
164
161
  "color-interpolation-filters",
165
162
  "color-scheme",
163
+ "columns",
166
164
  "column-count",
167
165
  "column-fill",
168
- "column-gap",
169
166
  "column-rule",
170
167
  "column-rule-color",
171
168
  "column-rule-style",
172
169
  "column-rule-width",
173
170
  "column-span",
174
171
  "column-width",
175
- "columns",
176
172
  "contain",
177
173
  "contain-intrinsic-size",
178
174
  "contain-intrinsic-width",
@@ -187,7 +183,6 @@ export const order = [
187
183
  "continue",
188
184
  "copy-into",
189
185
  "corner-shape",
190
- "corners",
191
186
  "counter-increment",
192
187
  "counter-reset",
193
188
  "counter-set",
@@ -261,6 +256,8 @@ export const order = [
261
256
  "footnote-policy",
262
257
  "forced-color-adjust",
263
258
  "gap",
259
+ "row-gap",
260
+ "column-gap",
264
261
  "glyph-orientation-vertical",
265
262
  "grid",
266
263
  "grid-gap",
@@ -304,9 +301,6 @@ export const order = [
304
301
  "inset-block-end",
305
302
  "interpolate-size",
306
303
  "isolation",
307
- "justify-content",
308
- "justify-items",
309
- "justify-self",
310
304
  "letter-spacing",
311
305
  "lighting-color",
312
306
  "line-break",
@@ -360,6 +354,7 @@ export const order = [
360
354
  "math-shift",
361
355
  "math-style",
362
356
  "max-lines",
357
+ "block-ellipsis",
363
358
  "min-intrinsic-sizing",
364
359
  "mix-blend-mode",
365
360
  "nav-up",
@@ -429,15 +424,21 @@ export const order = [
429
424
  "perspective",
430
425
  "perspective-origin",
431
426
  "place-content",
427
+ "align-content",
428
+ "justify-content",
432
429
  "place-items",
430
+ "align-items",
431
+ "justify-items",
433
432
  "place-self",
433
+ "align-self",
434
+ "justify-self",
434
435
  "pointer-events",
435
436
  "position",
436
437
  "position-anchor",
437
- "position-area",
438
438
  "position-try",
439
439
  "position-try-order",
440
440
  "position-try-fallbacks",
441
+ "position-area",
441
442
  "position-visibility",
442
443
  "print-color-adjust",
443
444
  "quotes",
@@ -449,7 +450,6 @@ export const order = [
449
450
  "rest-before",
450
451
  "rest-after",
451
452
  "rotate",
452
- "row-gap",
453
453
  "ruby-align",
454
454
  "ruby-merge",
455
455
  "ruby-overhang",
@@ -587,6 +587,8 @@ export const order = [
587
587
  "user-select",
588
588
  "vector-effect",
589
589
  "vertical-align",
590
+ "alignment-baseline",
591
+ "baseline-shift",
590
592
  "view-timeline",
591
593
  "view-timeline-axis",
592
594
  "view-timeline-inset",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrhenry/stylelint-mrhenry-prop-order",
3
- "version": "3.0.13",
3
+ "version": "3.0.15",
4
4
  "description": "Mr. Henry's preferred order for CSS properties",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
@@ -27,9 +27,10 @@
27
27
  "stylelint-plugin"
28
28
  ],
29
29
  "peerDependencies": {
30
- "stylelint": "^16.0.0"
30
+ "stylelint": "^16.8.2"
31
31
  },
32
32
  "devDependencies": {
33
- "stylelint": "^16.7.0"
33
+ "css-tree": "^2.3.1",
34
+ "stylelint": "^16.8.2"
34
35
  }
35
36
  }