eslint-plugin-perfectionist 2.7.0 → 2.9.0

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 (84) hide show
  1. package/dist/configs/recommended-alphabetical.js +9 -1
  2. package/dist/configs/recommended-alphabetical.mjs +5 -10
  3. package/dist/configs/recommended-line-length.js +9 -1
  4. package/dist/configs/recommended-line-length.mjs +5 -10
  5. package/dist/configs/recommended-natural.js +9 -1
  6. package/dist/configs/recommended-natural.mjs +5 -10
  7. package/dist/index.js +135 -3
  8. package/dist/index.mjs +76 -2197
  9. package/dist/package.json.js +4 -0
  10. package/dist/package.json.mjs +4 -0
  11. package/dist/rules/sort-array-includes.js +129 -0
  12. package/dist/rules/sort-array-includes.mjs +129 -0
  13. package/dist/rules/sort-astro-attributes.js +161 -0
  14. package/dist/rules/sort-astro-attributes.mjs +161 -0
  15. package/dist/rules/sort-classes.js +213 -0
  16. package/dist/rules/sort-classes.mjs +213 -0
  17. package/dist/rules/sort-enums.js +117 -0
  18. package/dist/rules/sort-enums.mjs +117 -0
  19. package/dist/rules/sort-exports.js +104 -0
  20. package/dist/rules/sort-exports.mjs +104 -0
  21. package/dist/rules/sort-imports.js +439 -0
  22. package/dist/rules/sort-imports.mjs +439 -0
  23. package/dist/rules/sort-interfaces.js +253 -0
  24. package/dist/rules/sort-interfaces.mjs +253 -0
  25. package/dist/rules/sort-intersection-types.js +92 -0
  26. package/dist/rules/sort-intersection-types.mjs +92 -0
  27. package/dist/rules/sort-jsx-props.js +156 -0
  28. package/dist/rules/sort-jsx-props.mjs +156 -0
  29. package/dist/rules/sort-maps.js +125 -0
  30. package/dist/rules/sort-maps.mjs +125 -0
  31. package/dist/rules/sort-named-exports.js +105 -0
  32. package/dist/rules/sort-named-exports.mjs +105 -0
  33. package/dist/rules/sort-named-imports.js +123 -0
  34. package/dist/rules/sort-named-imports.mjs +123 -0
  35. package/dist/rules/sort-object-types.js +189 -0
  36. package/dist/rules/sort-object-types.mjs +189 -0
  37. package/dist/rules/sort-objects.js +265 -0
  38. package/dist/rules/sort-objects.mjs +265 -0
  39. package/dist/rules/sort-svelte-attributes.js +168 -0
  40. package/dist/rules/sort-svelte-attributes.mjs +168 -0
  41. package/dist/rules/sort-union-types.js +120 -0
  42. package/dist/rules/sort-union-types.mjs +120 -0
  43. package/dist/rules/sort-vue-attributes.js +165 -0
  44. package/dist/rules/sort-vue-attributes.mjs +165 -0
  45. package/dist/typings/index.js +29 -0
  46. package/dist/typings/index.mjs +29 -0
  47. package/dist/utils/compare.js +38 -0
  48. package/dist/utils/compare.mjs +38 -0
  49. package/dist/utils/complete.js +4 -0
  50. package/dist/utils/complete.mjs +4 -0
  51. package/dist/utils/create-eslint-rule.js +7 -0
  52. package/dist/utils/create-eslint-rule.mjs +7 -0
  53. package/dist/utils/get-comment-after.js +13 -0
  54. package/dist/utils/get-comment-after.mjs +13 -0
  55. package/dist/utils/get-comment-before.js +14 -0
  56. package/dist/utils/get-comment-before.mjs +14 -0
  57. package/dist/utils/get-group-number.js +12 -0
  58. package/dist/utils/get-group-number.mjs +12 -0
  59. package/dist/utils/get-lines-between.js +10 -0
  60. package/dist/utils/get-lines-between.mjs +10 -0
  61. package/dist/utils/get-node-parent.js +14 -0
  62. package/dist/utils/get-node-parent.mjs +14 -0
  63. package/dist/utils/get-node-range.js +41 -0
  64. package/dist/utils/get-node-range.mjs +41 -0
  65. package/dist/utils/is-member-optional.js +12 -0
  66. package/dist/utils/is-member-optional.mjs +12 -0
  67. package/dist/utils/is-partition-comment.js +11 -0
  68. package/dist/utils/is-partition-comment.mjs +11 -0
  69. package/dist/utils/is-positive.js +4 -0
  70. package/dist/utils/is-positive.mjs +4 -0
  71. package/dist/utils/make-fixes.js +38 -0
  72. package/dist/utils/make-fixes.mjs +38 -0
  73. package/dist/utils/pairwise.js +14 -0
  74. package/dist/utils/pairwise.mjs +14 -0
  75. package/dist/utils/range-to-diff.js +7 -0
  76. package/dist/utils/range-to-diff.mjs +7 -0
  77. package/dist/utils/sort-nodes.js +5 -0
  78. package/dist/utils/sort-nodes.mjs +5 -0
  79. package/dist/utils/to-single-line.js +4 -0
  80. package/dist/utils/to-single-line.mjs +4 -0
  81. package/dist/utils/use-groups.js +35 -0
  82. package/dist/utils/use-groups.mjs +35 -0
  83. package/package.json +1 -1
  84. package/readme.md +20 -19
package/dist/index.mjs CHANGED
@@ -1,2148 +1,25 @@
1
- import W from "node:path";
2
- import { ESLintUtils as de, ASTUtils as K } from "@typescript-eslint/utils";
3
- import { minimatch as D } from "minimatch";
4
- import ce from "natural-compare-lite";
5
- import { builtinModules as fe } from "node:module";
6
- let A = de.RuleCreator(
7
- (e) => `https://eslint-plugin-perfectionist.azat.io/rules/${e}`
8
- ), h = (e, i) => {
9
- for (let s = 0, l = e.length; s < l; s++) {
10
- let r = e[s];
11
- if (i.group === r || Array.isArray(r) && typeof i.group == "string" && r.includes(i.group))
12
- return s;
13
- }
14
- return e.length;
15
- }, I = (e) => {
16
- let [i, s] = e;
17
- return s - i;
18
- }, O = (e) => e > 0;
19
- var u = /* @__PURE__ */ ((e) => (e.alphabetical = "alphabetical", e["line-length"] = "line-length", e.natural = "natural", e))(u || {}), g = /* @__PURE__ */ ((e) => (e.desc = "desc", e.asc = "asc", e))(g || {}), L = /* @__PURE__ */ ((e) => (e["values-first"] = "values-first", e["types-first"] = "types-first", e.mixed = "mixed", e))(L || {});
20
- let G = (e) => {
21
- let i, s = (r) => {
22
- !i && e.flat().includes(r) && (i = r);
23
- };
24
- return {
25
- getGroup: () => i ?? "unknown",
26
- setCustomGroups: (r, t) => {
27
- if (r)
28
- for (let [a, n] of Object.entries(r))
29
- Array.isArray(n) && n.some(
30
- (o) => D(t, o, {
31
- nocomment: !0
32
- })
33
- ) && s(a), typeof n == "string" && D(t, n, {
34
- nocomment: !0
35
- }) && s(a);
36
- },
37
- defineGroup: s
38
- };
39
- }, S = (e, i, s) => {
40
- var a, n;
41
- if ((a = i.dependencies) != null && a.includes(e.name))
42
- return -1;
43
- if ((n = e.dependencies) != null && n.includes(i.name))
44
- return 1;
45
- let l = s.order === "asc" ? 1 : -1, r, t = (o) => s["ignore-case"] ? o.toLowerCase() : o;
46
- return s.type === u.alphabetical ? r = (o, p) => t(o.name).localeCompare(t(p.name)) : s.type === u.natural ? r = (o, p) => ce(t(o.name), t(p.name)) : r = (o, p) => {
47
- let f = o.size, y = p.size, d = s["max-line-length"];
48
- if (d) {
49
- let c = (m, x) => m > d && x.hasMultipleImportDeclarations;
50
- c(f, o) && (f = o.name.length + 10), c(y, p) && (y = p.name.length + 10);
51
- }
52
- return f - y;
53
- }, l * r(e, i);
54
- }, v = (e, i) => [...e].sort((s, l) => S(s, l, i)), ge = (e, i) => {
55
- let s = i.getTokenAfter(e, {
56
- filter: ({ value: l, type: r }) => !(r === "Punctuator" && [",", ";"].includes(l)),
57
- includeComments: !0
58
- });
59
- return ((s == null ? void 0 : s.type) === "Block" || (s == null ? void 0 : s.type) === "Line") && e.loc.end.line === s.loc.end.line ? s : null;
60
- }, X = (e, i) => Array.isArray(e) && e.some(
61
- (s) => D(i.trim(), s, {
62
- nocomment: !0
63
- })
64
- ) || typeof e == "string" && D(i.trim(), e, {
65
- nocomment: !0
66
- }) || e === !0, V = (e, i) => {
67
- let [s, l] = i.getTokensBefore(e, {
68
- filter: ({ value: r, type: t }) => !(t === "Punctuator" && [",", ";"].includes(r)),
69
- includeComments: !0,
70
- count: 2
71
- });
72
- return ((l == null ? void 0 : l.type) === "Block" || (l == null ? void 0 : l.type) === "Line") && e.loc.start.line - l.loc.end.line <= 1 && (s == null ? void 0 : s.loc.end.line) !== l.loc.start.line ? l : null;
73
- }, T = (e, i, s) => {
74
- var n;
75
- let l = e.range.at(0), r = e.range.at(1), t = i.text.slice(l, r);
76
- if (K.isParenthesized(e, i)) {
77
- let o = i.getTokenBefore(
78
- e,
79
- K.isOpeningParenToken
80
- ), p = i.getTokenAfter(
81
- e,
82
- K.isClosingParenToken
83
- );
84
- l = o.range.at(0), r = p.range.at(1);
85
- }
86
- let a = V(e, i);
87
- if (t.endsWith(";") || t.endsWith(",")) {
88
- let o = i.getTokensAfter(e, {
89
- includeComments: !0,
90
- count: 2
91
- });
92
- e.loc.start.line === ((n = o.at(1)) == null ? void 0 : n.loc.start.line) && (r -= 1);
93
- }
94
- return a && !X(
95
- (s == null ? void 0 : s.partitionComment) ?? !1,
96
- a.value
97
- ) && (l = a.range.at(0)), [l, r];
98
- }, M = (e, i, s, l, r) => {
99
- var n, o;
100
- let t = [], a = ((n = i.at(0)) == null ? void 0 : n.node.loc.start.line) === ((o = i.at(-1)) == null ? void 0 : o.node.loc.end.line);
101
- for (let p = 0, f = i.length; p < f; p++) {
102
- let { node: y } = i.at(p);
103
- t.push(
104
- e.replaceTextRange(
105
- T(y, l, r),
106
- l.text.slice(
107
- ...T(s.at(p).node, l, r)
108
- )
109
- )
110
- );
111
- let d = ge(s.at(p).node, l);
112
- if (d && !a) {
113
- let m = [
114
- l.getTokenBefore(d).range.at(1),
115
- d.range.at(1)
116
- ];
117
- t.push(e.replaceTextRange(m, ""));
118
- let x = l.getTokenAfter(y);
119
- t.push(
120
- e.insertTextAfter(
121
- (x == null ? void 0 : x.loc.end.line) === y.loc.end.line ? x : y,
122
- l.text.slice(...m)
123
- )
124
- );
125
- }
126
- }
127
- return t;
128
- }, j = (e = {}, i) => Object.assign(i, e), P = (e, i) => {
129
- if (e.length > 1)
130
- for (let s = 1; s < e.length; s++) {
131
- let l = e.at(s - 1), r = e.at(s);
132
- l && r && i(l, r, s - 1);
133
- }
134
- };
135
- const q = "sort-svelte-attributes", ye = A({
136
- name: q,
137
- meta: {
138
- type: "suggestion",
139
- docs: {
140
- description: "enforce sorted Svelte attributes"
141
- },
142
- fixable: "code",
143
- schema: [
144
- {
145
- type: "object",
146
- properties: {
147
- "custom-groups": {
148
- type: "object"
149
- },
150
- type: {
151
- enum: [
152
- u.alphabetical,
153
- u.natural,
154
- u["line-length"]
155
- ],
156
- default: u.alphabetical,
157
- type: "string"
158
- },
159
- order: {
160
- enum: [g.asc, g.desc],
161
- default: g.asc,
162
- type: "string"
163
- },
164
- "ignore-case": {
165
- type: "boolean",
166
- default: !1
167
- },
168
- groups: {
169
- type: "array"
170
- }
171
- },
172
- additionalProperties: !1
173
- }
174
- ],
175
- messages: {
176
- unexpectedSvelteAttributesOrder: 'Expected "{{right}}" to come before "{{left}}"'
177
- }
178
- },
179
- defaultOptions: [
180
- {
181
- type: u.alphabetical,
182
- order: g.asc
183
- }
184
- ],
185
- create: (e) => W.extname(e.filename) !== ".svelte" ? {} : {
186
- SvelteStartTag: (i) => {
187
- if (i.attributes.length > 1) {
188
- let s = j(e.options.at(0), {
189
- type: u.alphabetical,
190
- order: g.asc,
191
- "ignore-case": !1,
192
- "custom-groups": {},
193
- groups: []
194
- }), l = i.attributes.reduce(
195
- (r, t) => {
196
- if (t.type === "SvelteSpreadAttribute")
197
- return r.push([]), r;
198
- let a, { getGroup: n, defineGroup: o, setCustomGroups: p } = G(
199
- s.groups
200
- );
201
- return t.key.type === "SvelteSpecialDirectiveKey" ? a = e.sourceCode.text.slice(...t.key.range) : typeof t.key.name == "string" ? { name: a } = t.key : a = e.sourceCode.text.slice(...t.key.range), p(s["custom-groups"], a), t.type === "SvelteShorthandAttribute" && (o("svelte-shorthand"), o("shorthand")), (!("value" in t) || Array.isArray(t.value) && !t.value.at(0)) && o("shorthand"), t.loc.start.line !== t.loc.end.line && o("multiline"), r.at(-1).push({
202
- size: I(t.range),
203
- node: t,
204
- group: n(),
205
- name: a
206
- }), r;
207
- },
208
- [[]]
209
- );
210
- for (let r of l)
211
- P(r, (t, a) => {
212
- let n = h(s.groups, t), o = h(s.groups, a);
213
- (n > o || n === o && O(S(t, a, s))) && e.report({
214
- messageId: "unexpectedSvelteAttributesOrder",
215
- data: {
216
- left: t.name,
217
- right: a.name
218
- },
219
- node: a.node,
220
- fix: (p) => {
221
- let f = {};
222
- for (let d of r) {
223
- let c = h(s.groups, d);
224
- c in f ? f[c] = v(
225
- [...f[c], d],
226
- s
227
- ) : f[c] = [d];
228
- }
229
- let y = [];
230
- for (let d of Object.keys(f).sort(
231
- (c, m) => Number(c) - Number(m)
232
- ))
233
- y.push(...v(f[d], s));
234
- return M(
235
- p,
236
- r,
237
- y,
238
- e.sourceCode
239
- );
240
- }
241
- });
242
- });
243
- }
244
- }
245
- }
246
- }), H = "sort-astro-attributes", me = A({
247
- name: H,
248
- meta: {
249
- type: "suggestion",
250
- docs: {
251
- description: "enforce sorted Astro attributes"
252
- },
253
- fixable: "code",
254
- schema: [
255
- {
256
- type: "object",
257
- properties: {
258
- "custom-groups": {
259
- type: "object"
260
- },
261
- type: {
262
- enum: [
263
- u.alphabetical,
264
- u.natural,
265
- u["line-length"]
266
- ],
267
- default: u.alphabetical,
268
- type: "string"
269
- },
270
- order: {
271
- enum: [g.asc, g.desc],
272
- default: g.asc,
273
- type: "string"
274
- },
275
- "ignore-case": {
276
- type: "boolean",
277
- default: !1
278
- },
279
- groups: {
280
- type: "array"
281
- }
282
- },
283
- additionalProperties: !1
284
- }
285
- ],
286
- messages: {
287
- unexpectedAstroAttributesOrder: 'Expected "{{right}}" to come before "{{left}}"'
288
- }
289
- },
290
- defaultOptions: [
291
- {
292
- type: u.alphabetical,
293
- order: g.asc
294
- }
295
- ],
296
- // @ts-ignore
297
- create: (e) => W.extname(e.filename) !== ".astro" ? {} : {
298
- JSXElement: (i) => {
299
- let { attributes: s } = i.openingElement;
300
- if (s.length > 1) {
301
- let l = j(e.options.at(0), {
302
- type: u.alphabetical,
303
- order: g.asc,
304
- "ignore-case": !1,
305
- "custom-groups": {},
306
- groups: []
307
- }), r = s.reduce(
308
- (t, a) => {
309
- if (a.type === "JSXSpreadAttribute")
310
- return t.push([]), t;
311
- let n = typeof a.name.name == "string" ? a.name.name : e.sourceCode.text.slice(...a.name.range), { getGroup: o, defineGroup: p, setCustomGroups: f } = G(
312
- l.groups
313
- );
314
- return f(l["custom-groups"], n), a.type === "AstroShorthandAttribute" && (p("astro-shorthand"), p("shorthand")), a.value === null && p("shorthand"), a.loc.start.line !== a.loc.end.line && p("multiline"), t.at(-1).push({
315
- size: I(a.range),
316
- node: a,
317
- group: o(),
318
- name: n
319
- }), t;
320
- },
321
- [[]]
322
- );
323
- for (let t of r)
324
- P(t, (a, n) => {
325
- let o = h(l.groups, a), p = h(l.groups, n);
326
- (o > p || o === p && O(S(a, n, l))) && e.report({
327
- messageId: "unexpectedAstroAttributesOrder",
328
- data: {
329
- left: a.name,
330
- right: n.name
331
- },
332
- node: n.node,
333
- fix: (f) => {
334
- let y = {};
335
- for (let c of t) {
336
- let m = h(l.groups, c);
337
- m in y ? y[m] = v(
338
- [...y[m], c],
339
- l
340
- ) : y[m] = [c];
341
- }
342
- let d = [];
343
- for (let c of Object.keys(y).sort(
344
- (m, x) => Number(m) - Number(x)
345
- ))
346
- d.push(...v(y[c], l));
347
- return M(
348
- f,
349
- t,
350
- d,
351
- e.sourceCode
352
- );
353
- }
354
- });
355
- });
356
- }
357
- }
358
- }
359
- });
360
- let k = (e) => e.replaceAll(/\s\s+/g, " ").trim();
361
- const Q = "sort-array-includes", he = A({
362
- name: Q,
363
- meta: {
364
- type: "suggestion",
365
- docs: {
366
- description: "enforce sorted arrays before include method"
367
- },
368
- fixable: "code",
369
- schema: [
370
- {
371
- type: "object",
372
- properties: {
373
- type: {
374
- enum: [
375
- u.alphabetical,
376
- u.natural,
377
- u["line-length"]
378
- ],
379
- default: u.alphabetical,
380
- type: "string"
381
- },
382
- order: {
383
- enum: [g.asc, g.desc],
384
- default: g.asc,
385
- type: "string"
386
- },
387
- "ignore-case": {
388
- type: "boolean",
389
- default: !1
390
- },
391
- "spread-last": {
392
- type: "boolean",
393
- default: !1
394
- }
395
- },
396
- additionalProperties: !1
397
- }
398
- ],
399
- messages: {
400
- unexpectedArrayIncludesOrder: 'Expected "{{right}}" to come before "{{left}}"'
401
- }
402
- },
403
- defaultOptions: [
404
- {
405
- type: u.alphabetical,
406
- order: g.asc
407
- }
408
- ],
409
- create: (e) => ({
410
- MemberExpression: (i) => {
411
- if ((i.object.type === "ArrayExpression" || i.object.type === "NewExpression") && i.property.type === "Identifier" && i.property.name === "includes") {
412
- let s = i.object.type === "ArrayExpression" ? i.object.elements : i.object.arguments;
413
- if (s.length > 1) {
414
- let l = j(e.options.at(0), {
415
- type: u.alphabetical,
416
- order: g.asc,
417
- "ignore-case": !1,
418
- "spread-last": !1
419
- }), r = s.reduce(
420
- (t, a) => (a !== null && t.at(0).push({
421
- name: a.type === "Literal" ? `${a.value}` : e.sourceCode.text.slice(...a.range),
422
- size: I(a.range),
423
- type: a.type,
424
- node: a
425
- }), t),
426
- [[], []]
427
- ).flat();
428
- P(r, (t, a) => {
429
- let n;
430
- l["spread-last"] && t.node.type === "Literal" && a.node.type === "SpreadElement" ? n = !1 : l["spread-last"] && t.node.type === "SpreadElement" && a.node.type === "Literal" ? n = !0 : n = O(S(t, a, l)), n && e.report({
431
- messageId: "unexpectedArrayIncludesOrder",
432
- data: {
433
- left: k(t.name),
434
- right: k(a.name)
435
- },
436
- node: a.node,
437
- fix: (o) => {
438
- let p = v(r, l);
439
- if (l["spread-last"])
440
- for (let f = 0, y = p.length; f < y; f++)
441
- p.at(f).node.type === "SpreadElement" && p.push(p.splice(f, 1).at(0));
442
- return M(
443
- o,
444
- r,
445
- p,
446
- e.sourceCode
447
- );
448
- }
449
- });
450
- });
451
- }
452
- }
453
- }
454
- })
455
- }), Y = "sort-vue-attributes", be = A({
456
- name: Y,
457
- meta: {
458
- type: "suggestion",
459
- docs: {
460
- description: "enforce sorted Vue attributes"
461
- },
462
- fixable: "code",
463
- schema: [
464
- {
465
- type: "object",
466
- properties: {
467
- "custom-groups": {
468
- type: "object"
469
- },
470
- type: {
471
- enum: [
472
- u.alphabetical,
473
- u.natural,
474
- u["line-length"]
475
- ],
476
- default: u.alphabetical,
477
- type: "string"
478
- },
479
- order: {
480
- enum: [g.asc, g.desc],
481
- default: g.asc,
482
- type: "string"
483
- },
484
- "ignore-case": {
485
- type: "boolean",
486
- default: !1
487
- },
488
- groups: {
489
- type: "array",
490
- default: []
491
- }
492
- },
493
- additionalProperties: !1
494
- }
495
- ],
496
- messages: {
497
- unexpectedVueAttributesOrder: 'Expected "{{right}}" to come before "{{left}}"'
498
- }
499
- },
500
- defaultOptions: [
501
- {
502
- type: u.alphabetical,
503
- order: g.asc
504
- }
505
- ],
506
- create: (e) => {
507
- if (W.extname(e.filename) !== ".vue")
508
- return {};
509
- if (!("defineTemplateBodyVisitor" in e.sourceCode.parserServices))
510
- return {};
511
- let { defineTemplateBodyVisitor: i } = e.sourceCode.parserServices;
512
- return i({
513
- VStartTag: (s) => {
514
- if (s.attributes.length > 1) {
515
- let l = j(e.options.at(0), {
516
- type: u.alphabetical,
517
- order: g.asc,
518
- "ignore-case": !1,
519
- "custom-groups": {},
520
- groups: []
521
- }), r = s.attributes.reduce(
522
- (t, a) => {
523
- if (a.key.type === "VDirectiveKey" && a.key.name.rawName === "bind")
524
- return t.push([]), t;
525
- let n, { getGroup: o, defineGroup: p, setCustomGroups: f } = G(
526
- l.groups
527
- );
528
- return typeof a.key.name == "string" && a.key.type !== "VDirectiveKey" ? n = a.key.rawName : n = e.sourceCode.text.slice(...a.key.range), f(l["custom-groups"], n), a.value === null && p("shorthand"), a.loc.start.line !== a.loc.end.line && p("multiline"), t.at(-1).push({
529
- size: I(a.range),
530
- node: a,
531
- group: o(),
532
- name: n
533
- }), t;
534
- },
535
- [[]]
536
- );
537
- for (let t of r)
538
- P(t, (a, n) => {
539
- let o = h(l.groups, a), p = h(l.groups, n);
540
- (o > p || o === p && O(S(a, n, l))) && e.report({
541
- messageId: "unexpectedVueAttributesOrder",
542
- data: {
543
- left: a.name,
544
- right: n.name
545
- },
546
- node: n.node,
547
- fix: (f) => {
548
- let y = {};
549
- for (let c of t) {
550
- let m = h(l.groups, c);
551
- m in y ? y[m] = v(
552
- [...y[m], c],
553
- l
554
- ) : y[m] = [c];
555
- }
556
- let d = [];
557
- for (let c of Object.keys(y).sort(
558
- (m, x) => Number(m) - Number(x)
559
- ))
560
- d.push(...v(y[c], l));
561
- return M(
562
- f,
563
- t,
564
- d,
565
- e.sourceCode
566
- );
567
- }
568
- });
569
- });
570
- }
571
- }
572
- });
573
- }
574
- }), Z = "sort-named-exports", xe = A({
575
- name: Z,
576
- meta: {
577
- type: "suggestion",
578
- docs: {
579
- description: "enforce sorted named exports"
580
- },
581
- fixable: "code",
582
- schema: [
583
- {
584
- type: "object",
585
- properties: {
586
- type: {
587
- enum: [
588
- u.alphabetical,
589
- u.natural,
590
- u["line-length"]
591
- ],
592
- default: u.alphabetical,
593
- type: "string"
594
- },
595
- order: {
596
- enum: [g.asc, g.desc],
597
- default: g.asc,
598
- type: "string"
599
- },
600
- "ignore-case": {
601
- type: "boolean",
602
- default: !1
603
- },
604
- "group-kind": {
605
- enum: [
606
- L.mixed,
607
- L["values-first"],
608
- L["types-first"]
609
- ],
610
- default: L.mixed,
611
- type: "string"
612
- }
613
- },
614
- additionalProperties: !1
615
- }
616
- ],
617
- messages: {
618
- unexpectedNamedExportsOrder: 'Expected "{{right}}" to come before "{{left}}"'
619
- }
620
- },
621
- defaultOptions: [
622
- {
623
- type: u.alphabetical,
624
- order: g.asc
625
- }
626
- ],
627
- create: (e) => ({
628
- ExportNamedDeclaration: (i) => {
629
- if (i.specifiers.length > 1) {
630
- let s = j(e.options.at(0), {
631
- type: u.alphabetical,
632
- "ignore-case": !1,
633
- order: g.asc,
634
- "group-kind": L.mixed
635
- }), l = i.specifiers.map((a) => ({
636
- size: I(a.range),
637
- name: a.local.name,
638
- node: a,
639
- group: a.exportKind
640
- })), r = s["group-kind"] !== L.mixed, t = s["group-kind"] === L["values-first"] ? ["value", "type"] : ["type", "value"];
641
- P(l, (a, n) => {
642
- let o = h(t, a), p = h(t, n);
643
- if (r && o > p || (!r || o === p) && O(S(a, n, s))) {
644
- let f = r ? t.map((y) => l.filter((d) => d.group === y)).map((y) => v(y, s)).flat() : v(l, s);
645
- e.report({
646
- messageId: "unexpectedNamedExportsOrder",
647
- data: {
648
- left: a.name,
649
- right: n.name
650
- },
651
- node: n.node,
652
- fix: (y) => M(y, l, f, e.sourceCode)
653
- });
654
- }
655
- });
656
- }
657
- }
658
- })
659
- }), F = "sort-named-imports", Ee = A({
660
- name: F,
661
- meta: {
662
- type: "suggestion",
663
- docs: {
664
- description: "enforce sorted named imports"
665
- },
666
- fixable: "code",
667
- schema: [
668
- {
669
- type: "object",
670
- properties: {
671
- type: {
672
- enum: [
673
- u.alphabetical,
674
- u.natural,
675
- u["line-length"]
676
- ],
677
- default: u.alphabetical,
678
- type: "string"
679
- },
680
- order: {
681
- enum: [g.asc, g.desc],
682
- default: g.asc,
683
- type: "string"
684
- },
685
- "ignore-case": {
686
- type: "boolean",
687
- default: !1
688
- },
689
- "ignore-alias": {
690
- type: "boolean",
691
- default: !1
692
- },
693
- "group-kind": {
694
- enum: [
695
- L.mixed,
696
- L["values-first"],
697
- L["types-first"]
698
- ],
699
- default: L.mixed,
700
- type: "string"
701
- }
702
- },
703
- additionalProperties: !1
704
- }
705
- ],
706
- messages: {
707
- unexpectedNamedImportsOrder: 'Expected "{{right}}" to come before "{{left}}"'
708
- }
709
- },
710
- defaultOptions: [
711
- {
712
- type: u.alphabetical,
713
- order: g.asc
714
- }
715
- ],
716
- create: (e) => ({
717
- ImportDeclaration: (i) => {
718
- let s = i.specifiers.filter(
719
- ({ type: l }) => l === "ImportSpecifier"
720
- );
721
- if (s.length > 1) {
722
- let l = j(e.options.at(0), {
723
- type: u.alphabetical,
724
- "ignore-alias": !0,
725
- "ignore-case": !1,
726
- order: g.asc,
727
- "group-kind": L.mixed
728
- }), r = s.map((n) => {
729
- let o, { name: p } = n.local;
730
- return n.type === "ImportSpecifier" && (l["ignore-alias"] && ({ name: p } = n.imported), o = n.importKind), {
731
- size: I(n.range),
732
- node: n,
733
- name: p,
734
- group: o
735
- };
736
- }), t = l["group-kind"] !== L.mixed, a = l["group-kind"] === L["values-first"] ? ["value", "type"] : ["type", "value"];
737
- P(r, (n, o) => {
738
- let p = h(a, n), f = h(a, o);
739
- if (t && p > f || (!t || p === f) && O(S(n, o, l))) {
740
- let y = t ? a.map((d) => r.filter((c) => c.group === d)).map((d) => v(d, l)).flat() : v(r, l);
741
- e.report({
742
- messageId: "unexpectedNamedImportsOrder",
743
- data: {
744
- left: n.name,
745
- right: o.name
746
- },
747
- node: o.node,
748
- fix: (d) => M(d, r, y, e.sourceCode)
749
- });
750
- }
751
- });
752
- }
753
- }
754
- })
755
- });
756
- let z = (e, i, s) => e.lines.slice(
757
- i.node.loc.end.line,
758
- s.node.loc.start.line - 1
759
- ).filter((r) => !r.trim().length).length;
760
- const ee = "sort-object-types", Ne = A({
761
- name: ee,
762
- meta: {
763
- type: "suggestion",
764
- docs: {
765
- description: "enforce sorted object types"
766
- },
767
- fixable: "code",
768
- schema: [
769
- {
770
- type: "object",
771
- properties: {
772
- "custom-groups": {
773
- type: "object"
774
- },
775
- type: {
776
- enum: [
777
- u.alphabetical,
778
- u.natural,
779
- u["line-length"]
780
- ],
781
- default: u.alphabetical,
782
- type: "string"
783
- },
784
- order: {
785
- enum: [g.asc, g.desc],
786
- default: g.asc,
787
- type: "string"
788
- },
789
- "ignore-case": {
790
- type: "boolean",
791
- default: !1
792
- },
793
- groups: {
794
- type: "array",
795
- default: []
796
- },
797
- "partition-by-new-line": {
798
- type: "boolean",
799
- default: !1
800
- }
801
- },
802
- additionalProperties: !1
803
- }
804
- ],
805
- messages: {
806
- unexpectedObjectTypesOrder: 'Expected "{{right}}" to come before "{{left}}"'
807
- }
808
- },
809
- defaultOptions: [
810
- {
811
- type: u.alphabetical,
812
- order: g.asc
813
- }
814
- ],
815
- create: (e) => ({
816
- TSTypeLiteral: (i) => {
817
- if (i.members.length > 1) {
818
- let s = j(e.options.at(0), {
819
- "partition-by-new-line": !1,
820
- type: u.alphabetical,
821
- "ignore-case": !1,
822
- order: g.asc,
823
- "custom-groups": {},
824
- groups: []
825
- }), l = i.members.reduce(
826
- (r, t) => {
827
- var C, b, N, E;
828
- let a, n = e.sourceCode.text.slice(
829
- t.range.at(0),
830
- t.range.at(1)
831
- ), o = (C = r.at(-1)) == null ? void 0 : C.at(-1), { getGroup: p, defineGroup: f, setCustomGroups: y } = G(
832
- s.groups
833
- ), d = (w) => w.replace(/(,|;)$/, "");
834
- if (t.type === "TSPropertySignature")
835
- t.key.type === "Identifier" ? { name: a } = t.key : t.key.type === "Literal" ? a = `${t.key.value}` : a = e.sourceCode.text.slice(
836
- t.range.at(0),
837
- (b = t.typeAnnotation) == null ? void 0 : b.range.at(0)
838
- );
839
- else if (t.type === "TSIndexSignature") {
840
- let w = ((N = t.typeAnnotation) == null ? void 0 : N.range.at(0)) ?? t.range.at(1);
841
- a = d(
842
- e.sourceCode.text.slice(t.range.at(0), w)
843
- );
844
- } else
845
- a = d(
846
- e.sourceCode.text.slice(
847
- t.range.at(0),
848
- t.range.at(1)
849
- )
850
- );
851
- y(s["custom-groups"], a), t.loc.start.line !== t.loc.end.line && f("multiline");
852
- let m = n.endsWith(";") || n.endsWith(",") ? 1 : 0, x = {
853
- size: I(t.range) - m,
854
- node: t,
855
- name: a
856
- };
857
- return s["partition-by-new-line"] && o && z(e.sourceCode, o, x) && r.push([]), (E = r.at(-1)) == null || E.push({
858
- ...x,
859
- group: p()
860
- }), r;
861
- },
862
- [[]]
863
- );
864
- for (let r of l)
865
- P(r, (t, a) => {
866
- let n = h(s.groups, t), o = h(s.groups, a);
867
- (n > o || n === o && O(S(t, a, s))) && e.report({
868
- messageId: "unexpectedObjectTypesOrder",
869
- data: {
870
- left: k(t.name),
871
- right: k(a.name)
872
- },
873
- node: a.node,
874
- fix: (p) => {
875
- let f = {};
876
- for (let d of r) {
877
- let c = h(s.groups, d);
878
- c in f ? f[c] = v(
879
- [...f[c], d],
880
- s
881
- ) : f[c] = [d];
882
- }
883
- let y = [];
884
- for (let d of Object.keys(f).sort(
885
- (c, m) => Number(c) - Number(m)
886
- ))
887
- y.push(...v(f[d], s));
888
- return M(
889
- p,
890
- r,
891
- y,
892
- e.sourceCode
893
- );
894
- }
895
- });
896
- });
897
- }
898
- }
899
- })
900
- }), te = "sort-union-types", Ce = A({
901
- name: te,
902
- meta: {
903
- type: "suggestion",
904
- docs: {
905
- description: "enforce sorted union types"
906
- },
907
- fixable: "code",
908
- schema: [
909
- {
910
- type: "object",
911
- properties: {
912
- type: {
913
- enum: [
914
- u.alphabetical,
915
- u.natural,
916
- u["line-length"]
917
- ],
918
- default: u.alphabetical,
919
- type: "string"
920
- },
921
- order: {
922
- enum: [g.asc, g.desc],
923
- default: g.asc,
924
- type: "string"
925
- },
926
- "ignore-case": {
927
- type: "boolean",
928
- default: !1
929
- },
930
- "nullable-last": {
931
- type: "boolean",
932
- default: !1
933
- }
934
- },
935
- additionalProperties: !1
936
- }
937
- ],
938
- messages: {
939
- unexpectedUnionTypesOrder: 'Expected "{{right}}" to come before "{{left}}"'
940
- }
941
- },
942
- defaultOptions: [
943
- {
944
- type: u.alphabetical,
945
- order: g.asc
946
- }
947
- ],
948
- create: (e) => ({
949
- TSUnionType: (i) => {
950
- let s = j(e.options.at(0), {
951
- type: u.alphabetical,
952
- "nullable-last": !1,
953
- "ignore-case": !1,
954
- order: g.asc
955
- }), l = i.types.map((r) => ({
956
- group: r.type === "TSNullKeyword" || r.type === "TSUndefinedKeyword" ? "nullable" : "unknown",
957
- name: e.sourceCode.text.slice(...r.range),
958
- size: I(r.range),
959
- node: r
960
- }));
961
- P(l, (r, t) => {
962
- let a = O(S(r, t, s));
963
- s["nullable-last"] && (r.group === "nullable" && t.group === "unknown" ? a = !0 : r.group === "unknown" && t.group === "nullable" && (a = !1)), a && e.report({
964
- messageId: "unexpectedUnionTypesOrder",
965
- data: {
966
- left: k(r.name),
967
- right: k(t.name)
968
- },
969
- node: t.node,
970
- fix: (n) => {
971
- let o = [];
972
- if (s["nullable-last"]) {
973
- let p = [], f = l.filter((y) => y.group === "nullable" ? (p.push(y), !1) : !0);
974
- o = [
975
- ...v(f, s),
976
- ...v(p, s)
977
- ];
978
- } else
979
- o = v(l, s);
980
- return M(n, l, o, e.sourceCode);
981
- }
982
- });
983
- });
984
- }
985
- })
986
- }), re = "sort-interfaces", ve = A({
987
- name: re,
988
- meta: {
989
- type: "suggestion",
990
- docs: {
991
- description: "enforce sorted interface properties"
992
- },
993
- fixable: "code",
994
- schema: [
995
- {
996
- type: "object",
997
- properties: {
998
- "custom-groups": {
999
- type: "object"
1000
- },
1001
- type: {
1002
- enum: [
1003
- u.alphabetical,
1004
- u.natural,
1005
- u["line-length"]
1006
- ],
1007
- default: u.alphabetical,
1008
- type: "string"
1009
- },
1010
- order: {
1011
- enum: [g.asc, g.desc],
1012
- default: g.asc,
1013
- type: "string"
1014
- },
1015
- "ignore-case": {
1016
- type: "boolean",
1017
- default: !1
1018
- },
1019
- "ignore-pattern": {
1020
- items: {
1021
- type: "string"
1022
- },
1023
- type: "array"
1024
- },
1025
- groups: {
1026
- type: "array",
1027
- default: []
1028
- },
1029
- "partition-by-new-line": {
1030
- type: "boolean",
1031
- default: !1
1032
- }
1033
- },
1034
- additionalProperties: !1
1035
- }
1036
- ],
1037
- messages: {
1038
- unexpectedInterfacePropertiesOrder: 'Expected "{{right}}" to come before "{{left}}"'
1039
- }
1040
- },
1041
- defaultOptions: [
1042
- {
1043
- type: u.alphabetical,
1044
- order: g.asc
1045
- }
1046
- ],
1047
- create: (e) => ({
1048
- TSInterfaceDeclaration: (i) => {
1049
- if (i.body.body.length > 1) {
1050
- let s = j(e.options.at(0), {
1051
- "partition-by-new-line": !1,
1052
- type: u.alphabetical,
1053
- "ignore-case": !1,
1054
- order: g.asc,
1055
- "ignore-pattern": [],
1056
- "custom-groups": {},
1057
- groups: []
1058
- });
1059
- if (!s["ignore-pattern"].some(
1060
- (l) => D(i.id.name, l, {
1061
- nocomment: !0
1062
- })
1063
- )) {
1064
- let l = i.body.body.reduce(
1065
- (r, t) => {
1066
- var d, c, m, x;
1067
- if (t.type === "TSCallSignatureDeclaration")
1068
- return r.push([]), r;
1069
- let a = (d = r.at(-1)) == null ? void 0 : d.at(-1), n, { getGroup: o, defineGroup: p, setCustomGroups: f } = G(
1070
- s.groups
1071
- );
1072
- if (t.type === "TSPropertySignature")
1073
- if (t.key.type === "Identifier")
1074
- ({ name: n } = t.key);
1075
- else if (t.key.type === "Literal")
1076
- n = `${t.key.value}`;
1077
- else {
1078
- let C = ((c = t.typeAnnotation) == null ? void 0 : c.range.at(0)) ?? t.range.at(1) - (t.optional ? 1 : 0);
1079
- n = e.sourceCode.text.slice(t.range.at(0), C);
1080
- }
1081
- else if (t.type === "TSIndexSignature") {
1082
- let C = ((m = t.typeAnnotation) == null ? void 0 : m.range.at(0)) ?? t.range.at(1);
1083
- n = e.sourceCode.text.slice(
1084
- t.range.at(0),
1085
- C
1086
- );
1087
- } else {
1088
- let C = ((x = t.returnType) == null ? void 0 : x.range.at(0)) ?? t.range.at(1);
1089
- n = e.sourceCode.text.slice(
1090
- t.range.at(0),
1091
- C
1092
- );
1093
- }
1094
- let y = {
1095
- size: I(t.range),
1096
- node: t,
1097
- name: n
1098
- };
1099
- return s["partition-by-new-line"] && a && z(
1100
- e.sourceCode,
1101
- a,
1102
- y
1103
- ) && r.push([]), f(s["custom-groups"], n), t.loc.start.line !== t.loc.end.line && p("multiline"), r.at(-1).push({
1104
- ...y,
1105
- group: o()
1106
- }), r;
1107
- },
1108
- [[]]
1109
- );
1110
- for (let r of l)
1111
- P(r, (t, a) => {
1112
- let n = h(s.groups, t), o = h(s.groups, a);
1113
- (n > o || n === o && O(S(t, a, s))) && e.report({
1114
- messageId: "unexpectedInterfacePropertiesOrder",
1115
- data: {
1116
- left: k(t.name),
1117
- right: k(a.name)
1118
- },
1119
- node: a.node,
1120
- fix: (p) => {
1121
- let f = {};
1122
- for (let d of r) {
1123
- let c = h(s.groups, d);
1124
- c in f ? f[c] = v(
1125
- [...f[c], d],
1126
- s
1127
- ) : f[c] = [d];
1128
- }
1129
- let y = [];
1130
- for (let d of Object.keys(f).sort(
1131
- (c, m) => Number(c) - Number(m)
1132
- ))
1133
- y.push(...v(f[d], s));
1134
- return M(
1135
- p,
1136
- r,
1137
- y,
1138
- e.sourceCode
1139
- );
1140
- }
1141
- });
1142
- });
1143
- }
1144
- }
1145
- }
1146
- })
1147
- }), se = "sort-jsx-props", we = A({
1148
- name: se,
1149
- meta: {
1150
- type: "suggestion",
1151
- docs: {
1152
- description: "enforce sorted JSX props"
1153
- },
1154
- fixable: "code",
1155
- schema: [
1156
- {
1157
- type: "object",
1158
- properties: {
1159
- "custom-groups": {
1160
- type: "object"
1161
- },
1162
- type: {
1163
- enum: [
1164
- u.alphabetical,
1165
- u.natural,
1166
- u["line-length"]
1167
- ],
1168
- default: u.alphabetical,
1169
- type: "string"
1170
- },
1171
- order: {
1172
- enum: [g.asc, g.desc],
1173
- default: g.asc,
1174
- type: "string"
1175
- },
1176
- groups: {
1177
- type: "array"
1178
- },
1179
- "ignore-case": {
1180
- type: "boolean",
1181
- default: !1
1182
- }
1183
- },
1184
- additionalProperties: !1
1185
- }
1186
- ],
1187
- messages: {
1188
- unexpectedJSXPropsOrder: 'Expected "{{right}}" to come before "{{left}}"'
1189
- }
1190
- },
1191
- defaultOptions: [
1192
- {
1193
- type: u.alphabetical,
1194
- order: g.asc
1195
- }
1196
- ],
1197
- create: (e) => [".svelte", ".astro", ".vue"].includes(W.extname(e.filename)) ? {} : {
1198
- JSXElement: (i) => {
1199
- if (i.openingElement.attributes.length > 1) {
1200
- let s = j(e.options.at(0), {
1201
- type: u.alphabetical,
1202
- "ignore-case": !1,
1203
- order: g.asc,
1204
- "custom-groups": {},
1205
- groups: []
1206
- }), l = i.openingElement.attributes.reduce(
1207
- (r, t) => {
1208
- if (t.type === "JSXSpreadAttribute")
1209
- return r.push([]), r;
1210
- let a = t.name.type === "JSXNamespacedName" ? `${t.name.namespace.name}:${t.name.name.name}` : t.name.name, { getGroup: n, defineGroup: o, setCustomGroups: p } = G(
1211
- s.groups
1212
- );
1213
- p(s["custom-groups"], a), t.value === null && o("shorthand"), t.loc.start.line !== t.loc.end.line && o("multiline");
1214
- let f = {
1215
- size: I(t.range),
1216
- group: n(),
1217
- node: t,
1218
- name: a
1219
- };
1220
- return r.at(-1).push(f), r;
1221
- },
1222
- [[]]
1223
- );
1224
- for (let r of l)
1225
- P(r, (t, a) => {
1226
- let n = h(s.groups, t), o = h(s.groups, a);
1227
- (n > o || n === o && O(S(t, a, s))) && e.report({
1228
- messageId: "unexpectedJSXPropsOrder",
1229
- data: {
1230
- left: t.name,
1231
- right: a.name
1232
- },
1233
- node: a.node,
1234
- fix: (p) => {
1235
- let f = {};
1236
- for (let d of r) {
1237
- let c = h(s.groups, d);
1238
- c in f ? f[c] = v(
1239
- [...f[c], d],
1240
- s
1241
- ) : f[c] = [d];
1242
- }
1243
- let y = [];
1244
- for (let d of Object.keys(f).sort(
1245
- (c, m) => Number(c) - Number(m)
1246
- ))
1247
- y.push(...v(f[d], s));
1248
- return M(
1249
- p,
1250
- r,
1251
- y,
1252
- e.sourceCode
1253
- );
1254
- }
1255
- });
1256
- });
1257
- }
1258
- }
1259
- }
1260
- }), ae = "sort-exports", Se = A({
1261
- name: ae,
1262
- meta: {
1263
- type: "suggestion",
1264
- docs: {
1265
- description: "enforce sorted exports"
1266
- },
1267
- fixable: "code",
1268
- schema: [
1269
- {
1270
- type: "object",
1271
- properties: {
1272
- type: {
1273
- enum: [
1274
- u.alphabetical,
1275
- u.natural,
1276
- u["line-length"]
1277
- ],
1278
- default: u.alphabetical,
1279
- type: "string"
1280
- },
1281
- order: {
1282
- enum: [g.asc, g.desc],
1283
- default: g.asc,
1284
- type: "string"
1285
- },
1286
- "ignore-case": {
1287
- type: "boolean",
1288
- default: !1
1289
- }
1290
- },
1291
- additionalProperties: !1
1292
- }
1293
- ],
1294
- messages: {
1295
- unexpectedExportsOrder: 'Expected "{{right}}" to come before "{{left}}"'
1296
- }
1297
- },
1298
- defaultOptions: [
1299
- {
1300
- type: u.alphabetical,
1301
- order: g.asc
1302
- }
1303
- ],
1304
- create: (e) => {
1305
- let i = j(e.options.at(0), {
1306
- type: u.alphabetical,
1307
- order: g.asc,
1308
- "ignore-case": !1
1309
- }), s = [[]], l = (r) => {
1310
- r.type === "ExportAllDeclaration" && r.exported === null ? s.push([]) : s.at(-1).push({
1311
- size: I(r.range),
1312
- name: r.source.value,
1313
- node: r
1314
- });
1315
- };
1316
- return {
1317
- ExportAllDeclaration: l,
1318
- ExportNamedDeclaration: (r) => {
1319
- r.source !== null && l(r);
1320
- },
1321
- "Program:exit": () => {
1322
- for (let r of s)
1323
- P(r, (t, a) => {
1324
- O(S(t, a, i)) && e.report({
1325
- messageId: "unexpectedExportsOrder",
1326
- data: {
1327
- left: t.name,
1328
- right: a.name
1329
- },
1330
- node: a.node,
1331
- fix: (n) => M(
1332
- n,
1333
- r,
1334
- v(r, i),
1335
- e.sourceCode
1336
- )
1337
- });
1338
- });
1339
- }
1340
- };
1341
- }
1342
- }), oe = "sort-imports", ke = A({
1343
- name: oe,
1344
- meta: {
1345
- type: "suggestion",
1346
- docs: {
1347
- description: "enforce sorted imports"
1348
- },
1349
- fixable: "code",
1350
- schema: [
1351
- {
1352
- id: "sort-imports",
1353
- type: "object",
1354
- properties: {
1355
- "custom-groups": {
1356
- type: "object",
1357
- properties: {
1358
- type: {
1359
- type: "object"
1360
- },
1361
- value: {
1362
- type: "object"
1363
- }
1364
- },
1365
- additionalProperties: !1
1366
- },
1367
- type: {
1368
- enum: [
1369
- u.alphabetical,
1370
- u.natural,
1371
- u["line-length"]
1372
- ],
1373
- default: u.alphabetical,
1374
- type: "string"
1375
- },
1376
- order: {
1377
- enum: [g.asc, g.desc],
1378
- default: g.asc,
1379
- type: "string"
1380
- },
1381
- "ignore-case": {
1382
- type: "boolean",
1383
- default: !1
1384
- },
1385
- groups: {
1386
- type: "array",
1387
- default: []
1388
- },
1389
- "internal-pattern": {
1390
- items: {
1391
- type: "string"
1392
- },
1393
- type: "array"
1394
- },
1395
- "newlines-between": {
1396
- enum: [
1397
- "ignore",
1398
- "always",
1399
- "never"
1400
- /* never */
1401
- ],
1402
- default: "always",
1403
- type: "string"
1404
- },
1405
- "max-line-length": {
1406
- type: "integer",
1407
- minimum: 0,
1408
- exclusiveMinimum: !0
1409
- }
1410
- },
1411
- allOf: [
1412
- { $ref: "#/definitions/max-line-length-requires-line-length-type" }
1413
- ],
1414
- additionalProperties: !1,
1415
- dependencies: {
1416
- "max-line-length": ["type"]
1417
- },
1418
- definitions: {
1419
- "is-line-length": {
1420
- properties: {
1421
- type: { enum: [u["line-length"]], type: "string" }
1422
- },
1423
- required: ["type"],
1424
- type: "object"
1425
- },
1426
- "max-line-length-requires-line-length-type": {
1427
- anyOf: [
1428
- {
1429
- not: { required: ["max-line-length"], type: "object" },
1430
- type: "object"
1431
- },
1432
- { $ref: "#/definitions/is-line-length" }
1433
- ]
1434
- }
1435
- }
1436
- }
1437
- ],
1438
- messages: {
1439
- unexpectedImportsOrder: 'Expected "{{right}}" to come before "{{left}}"',
1440
- missedSpacingBetweenImports: 'Missed spacing between "{{left}}" and "{{right}}" imports',
1441
- extraSpacingBetweenImports: 'Extra spacing between "{{left}}" and "{{right}}" imports'
1442
- }
1443
- },
1444
- defaultOptions: [
1445
- {
1446
- type: u.alphabetical,
1447
- order: g.asc
1448
- }
1449
- ],
1450
- create: (e) => {
1451
- let i = j(e.options.at(0), {
1452
- "newlines-between": "always",
1453
- "custom-groups": { type: {}, value: {} },
1454
- "internal-pattern": ["~/**"],
1455
- type: u.alphabetical,
1456
- order: g.asc,
1457
- "ignore-case": !1,
1458
- groups: []
1459
- }), s = !1;
1460
- for (let o of i.groups)
1461
- if (Array.isArray(o))
1462
- for (let p of o)
1463
- p === "unknown" && (s = !0);
1464
- else
1465
- o === "unknown" && (s = !0);
1466
- s || (i.groups = [...i.groups, "unknown"]);
1467
- let l = [], r = (o) => o.type === "ImportDeclaration" && o.specifiers.length === 0, t = (o) => {
1468
- let p = (E) => [".less", ".scss", ".sass", ".styl", ".pcss", ".css", ".sss"].some(
1469
- (w) => E.endsWith(w)
1470
- ), f = (E) => [
1471
- "./index.d.js",
1472
- "./index.d.ts",
1473
- "./index.js",
1474
- "./index.ts",
1475
- "./index",
1476
- "./",
1477
- "."
1478
- ].includes(E), y = (E) => E.indexOf("..") === 0, d = (E) => E.indexOf("./") === 0, { getGroup: c, defineGroup: m, setCustomGroups: x } = G(i.groups), C = (E) => i["internal-pattern"].length && i["internal-pattern"].some(
1479
- (w) => D(E.source.value, w, {
1480
- nocomment: !0
1481
- })
1482
- ), b = (E) => {
1483
- let w = [
1484
- "bun",
1485
- "bun:ffi",
1486
- "bun:jsc",
1487
- "bun:sqlite",
1488
- "bun:test",
1489
- "bun:wrap",
1490
- "detect-libc",
1491
- "undici",
1492
- "ws"
1493
- ];
1494
- return fe.includes(
1495
- E.startsWith("node:") ? E.split("node:")[1] : E
1496
- ) || w.includes(E);
1497
- }, N = (E) => !(E.startsWith(".") || E.startsWith("/"));
1498
- return o.importKind === "type" && (o.type === "ImportDeclaration" && (x(i["custom-groups"].type, o.source.value), f(o.source.value) && m("index-type"), d(o.source.value) && m("sibling-type"), y(o.source.value) && m("parent-type"), C(o) && m("internal-type"), b(o.source.value) && m("builtin-type"), N(o.source.value) && m("external-type")), m("type")), o.type === "ImportDeclaration" && (x(i["custom-groups"].value, o.source.value), r(o) && p(o.source.value) && m("side-effect-style"), r(o) && m("side-effect"), p(o.source.value) && m("style"), f(o.source.value) && m("index"), d(o.source.value) && m("sibling"), y(o.source.value) && m("parent"), C(o) && m("internal"), b(o.source.value) && m("builtin"), N(o.source.value) && m("external")), c();
1499
- }, a = (o) => o.specifiers.length > 1, n = (o) => {
1500
- let p;
1501
- o.type === "ImportDeclaration" ? p = o.source.value : o.moduleReference.type === "TSExternalModuleReference" && o.moduleReference.expression.type === "Literal" ? p = `${o.moduleReference.expression.value}` : p = e.sourceCode.text.slice(...o.moduleReference.range), l.push({
1502
- size: I(o.range),
1503
- group: t(o),
1504
- name: p,
1505
- node: o,
1506
- ...i.type === u["line-length"] && i["max-line-length"] && {
1507
- hasMultipleImportDeclarations: a(
1508
- o
1509
- )
1510
- }
1511
- });
1512
- };
1513
- return {
1514
- TSImportEqualsDeclaration: n,
1515
- ImportDeclaration: n,
1516
- "Program:exit": () => {
1517
- var y;
1518
- let o = (d, c) => !!e.sourceCode.getTokensBetween(
1519
- d.node,
1520
- V(c.node, e.sourceCode) || c.node,
1521
- {
1522
- includeComments: !0
1523
- }
1524
- ).length, p = (d, c) => {
1525
- let m = [], x = {};
1526
- for (let b of c) {
1527
- let N = h(i.groups, b);
1528
- N in x ? x[N] = v(
1529
- [...x[N], b],
1530
- i
1531
- ) : x[N] = [b];
1532
- }
1533
- let C = Object.keys(x).sort((b, N) => Number(b) - Number(N)).reduce(
1534
- (b, N) => [
1535
- ...b,
1536
- ...x[N]
1537
- ],
1538
- []
1539
- );
1540
- for (let b = 0, N = C.length; b < N; b++) {
1541
- let E = C.at(b);
1542
- if (m.push(
1543
- d.replaceTextRange(
1544
- T(c.at(b).node, e.sourceCode),
1545
- e.sourceCode.text.slice(
1546
- ...T(E.node, e.sourceCode)
1547
- )
1548
- )
1549
- ), i["newlines-between"] !== "ignore") {
1550
- let w = C.at(b + 1);
1551
- if (w) {
1552
- let R = z(
1553
- e.sourceCode,
1554
- c.at(b),
1555
- c.at(b + 1)
1556
- );
1557
- (i["newlines-between"] === "always" && h(i.groups, E) === h(i.groups, w) && R !== 0 || i["newlines-between"] === "never" && R > 0) && m.push(
1558
- d.removeRange([
1559
- T(
1560
- c.at(b).node,
1561
- e.sourceCode
1562
- ).at(1),
1563
- T(
1564
- c.at(b + 1).node,
1565
- e.sourceCode
1566
- ).at(0) - 1
1567
- ])
1568
- ), i["newlines-between"] === "always" && h(i.groups, E) !== h(i.groups, w) && R > 1 && m.push(
1569
- d.replaceTextRange(
1570
- [
1571
- T(
1572
- c.at(b).node,
1573
- e.sourceCode
1574
- ).at(1),
1575
- T(
1576
- c.at(b + 1).node,
1577
- e.sourceCode
1578
- ).at(0) - 1
1579
- ],
1580
- `
1581
- `
1582
- )
1583
- ), i["newlines-between"] === "always" && h(i.groups, E) !== h(i.groups, w) && R === 0 && m.push(
1584
- d.insertTextAfterRange(
1585
- T(c.at(b).node, e.sourceCode),
1586
- `
1587
- `
1588
- )
1589
- );
1590
- }
1591
- }
1592
- }
1593
- return m;
1594
- }, f = [[]];
1595
- for (let d of l) {
1596
- let c = (y = f.at(-1)) == null ? void 0 : y.at(-1);
1597
- c && o(c, d) ? f.push([d]) : f.at(-1).push(d);
1598
- }
1599
- for (let d of f)
1600
- P(d, (c, m) => {
1601
- let x = h(i.groups, c), C = h(i.groups, m), b = z(
1602
- e.sourceCode,
1603
- c,
1604
- m
1605
- );
1606
- !(r(c.node) && r(m.node)) && !o(c, m) && (x > C || x === C && O(S(c, m, i))) && e.report({
1607
- messageId: "unexpectedImportsOrder",
1608
- data: {
1609
- left: c.name,
1610
- right: m.name
1611
- },
1612
- node: m.node,
1613
- fix: (N) => p(N, d)
1614
- }), i["newlines-between"] === "never" && b > 0 && e.report({
1615
- messageId: "extraSpacingBetweenImports",
1616
- data: {
1617
- left: c.name,
1618
- right: m.name
1619
- },
1620
- node: m.node,
1621
- fix: (N) => p(N, d)
1622
- }), i["newlines-between"] === "always" && (x < C && b === 0 ? e.report({
1623
- messageId: "missedSpacingBetweenImports",
1624
- data: {
1625
- left: c.name,
1626
- right: m.name
1627
- },
1628
- node: m.node,
1629
- fix: (N) => p(N, d)
1630
- }) : (b > 1 || x === C && b > 0) && e.report({
1631
- messageId: "extraSpacingBetweenImports",
1632
- data: {
1633
- left: c.name,
1634
- right: m.name
1635
- },
1636
- node: m.node,
1637
- fix: (N) => p(N, d)
1638
- }));
1639
- });
1640
- }
1641
- };
1642
- }
1643
- }), ne = "sort-objects", Ae = A({
1644
- name: ne,
1645
- meta: {
1646
- type: "suggestion",
1647
- docs: {
1648
- description: "enforce sorted objects"
1649
- },
1650
- fixable: "code",
1651
- schema: [
1652
- {
1653
- type: "object",
1654
- properties: {
1655
- "custom-groups": {
1656
- type: "object"
1657
- },
1658
- "partition-by-comment": {
1659
- type: ["boolean", "string", "array"],
1660
- default: !1
1661
- },
1662
- "partition-by-new-line": {
1663
- type: "boolean",
1664
- default: !1
1665
- },
1666
- "styled-components": {
1667
- type: "boolean",
1668
- default: !0
1669
- },
1670
- type: {
1671
- enum: [
1672
- u.alphabetical,
1673
- u.natural,
1674
- u["line-length"]
1675
- ],
1676
- default: u.alphabetical,
1677
- type: "string"
1678
- },
1679
- order: {
1680
- enum: [g.asc, g.desc],
1681
- default: g.asc,
1682
- type: "string"
1683
- },
1684
- "ignore-case": {
1685
- type: "boolean",
1686
- default: !1
1687
- },
1688
- "ignore-pattern": {
1689
- items: {
1690
- type: "string"
1691
- },
1692
- type: "array"
1693
- },
1694
- groups: {
1695
- type: "array"
1696
- }
1697
- },
1698
- additionalProperties: !1
1699
- }
1700
- ],
1701
- messages: {
1702
- unexpectedObjectsOrder: 'Expected "{{right}}" to come before "{{left}}"'
1703
- }
1704
- },
1705
- defaultOptions: [
1706
- {
1707
- type: u.alphabetical,
1708
- order: g.asc
1709
- }
1710
- ],
1711
- create: (e) => {
1712
- let i = (s) => {
1713
- let l = j(e.options.at(0), {
1714
- "partition-by-new-line": !1,
1715
- "partition-by-comment": !1,
1716
- type: u.alphabetical,
1717
- "styled-components": !0,
1718
- "ignore-case": !1,
1719
- "ignore-pattern": [],
1720
- order: g.asc,
1721
- "custom-groups": {},
1722
- groups: []
1723
- }), r = s.parent.type === "VariableDeclarator" && s.parent.id.type === "Identifier" ? s.parent.id.name : null;
1724
- if (!(l["ignore-pattern"].length && typeof r == "string" ? l["ignore-pattern"].some(
1725
- (a) => D(r, a, {
1726
- nocomment: !0
1727
- })
1728
- ) : !1) && s.properties.length > 1) {
1729
- let a = (p) => p.type === "Identifier" && p.name === "styled", n = (p) => p !== void 0 && p.type === "CallExpression" && (p.callee.type === "MemberExpression" && a(p.callee.object) || p.callee.type === "CallExpression" && a(p.callee.callee));
1730
- if (!l["styled-components"] && (n(s.parent) || s.parent.type === "ArrowFunctionExpression" && n(s.parent.parent)))
1731
- return;
1732
- let o = (p) => p.reduce(
1733
- (f, y) => {
1734
- var R;
1735
- if (y.type === "SpreadElement" || y.type === "RestElement")
1736
- return f.push([]), f;
1737
- let d = V(y, e.sourceCode), c = (R = f.at(-1)) == null ? void 0 : R.at(-1);
1738
- l["partition-by-comment"] && d && X(
1739
- l["partition-by-comment"],
1740
- d.value
1741
- ) && f.push([]);
1742
- let m, x = "ignore", C = [], { getGroup: b, setCustomGroups: N } = G(l.groups);
1743
- y.key.type === "Identifier" ? { name: m } = y.key : y.key.type === "Literal" ? m = `${y.key.value}` : m = e.sourceCode.text.slice(...y.key.range);
1744
- let E = {
1745
- size: I(y.range),
1746
- node: y,
1747
- name: m
1748
- };
1749
- l["partition-by-new-line"] && c && z(e.sourceCode, c, E) && f.push([]), y.value.type === "AssignmentPattern" && ((_) => {
1750
- _.right.type === "Identifier" && C.push(_.right.name);
1751
- let ue = ($) => {
1752
- let B = [];
1753
- switch ($.type) {
1754
- case "ArrowFunctionExpression":
1755
- B.push($.body);
1756
- break;
1757
- case "ConditionalExpression":
1758
- B.push($.consequent, $.alternate);
1759
- break;
1760
- case "LogicalExpression":
1761
- case "BinaryExpression":
1762
- B.push($.left, $.right);
1763
- break;
1764
- case "CallExpression":
1765
- B.push(...$.arguments);
1766
- break;
1767
- }
1768
- B.forEach((U) => {
1769
- U.type === "Identifier" && C.push(U.name), (U.type === "BinaryExpression" || U.type === "ConditionalExpression") && ue(U);
1770
- });
1771
- };
1772
- switch (_.right.type) {
1773
- case "ArrowFunctionExpression":
1774
- case "ConditionalExpression":
1775
- case "LogicalExpression":
1776
- case "BinaryExpression":
1777
- case "CallExpression":
1778
- ue(_.right);
1779
- break;
1780
- }
1781
- })(y.value), N(l["custom-groups"], m);
1782
- let w = {
1783
- ...E,
1784
- group: b(),
1785
- dependencies: C,
1786
- position: x
1787
- };
1788
- return f.at(-1).push(w), f;
1789
- },
1790
- [[]]
1791
- );
1792
- for (let p of o(s.properties))
1793
- P(p, (f, y) => {
1794
- let d = h(l.groups, f), c = h(l.groups, y);
1795
- if (d > c || d === c && O(S(f, y, l))) {
1796
- let m = (x) => {
1797
- let C = {};
1798
- for (let N of p) {
1799
- let E = h(l.groups, N);
1800
- E in C ? C[E] = v(
1801
- [...C[E], N],
1802
- l
1803
- ) : C[E] = [N];
1804
- }
1805
- let b = [];
1806
- for (let N of Object.keys(C).sort(
1807
- (E, w) => Number(E) - Number(w)
1808
- ))
1809
- b.push(...v(C[N], l));
1810
- return M(
1811
- x,
1812
- p,
1813
- b,
1814
- e.sourceCode,
1815
- {
1816
- partitionComment: l["partition-by-comment"]
1817
- }
1818
- );
1819
- };
1820
- e.report({
1821
- messageId: "unexpectedObjectsOrder",
1822
- data: {
1823
- left: k(f.name),
1824
- right: k(y.name)
1825
- },
1826
- node: y.node,
1827
- fix: m
1828
- });
1829
- }
1830
- });
1831
- }
1832
- };
1833
- return {
1834
- ObjectExpression: i,
1835
- ObjectPattern: i
1836
- };
1837
- }
1838
- }), le = "sort-classes", Ie = A({
1839
- name: le,
1840
- meta: {
1841
- type: "suggestion",
1842
- docs: {
1843
- description: "enforce sorted classes"
1844
- },
1845
- fixable: "code",
1846
- schema: [
1847
- {
1848
- type: "object",
1849
- properties: {
1850
- type: {
1851
- enum: [
1852
- u.alphabetical,
1853
- u.natural,
1854
- u["line-length"]
1855
- ],
1856
- default: u.alphabetical,
1857
- type: "string"
1858
- },
1859
- "ignore-case": {
1860
- type: "boolean",
1861
- default: !1
1862
- },
1863
- order: {
1864
- enum: [g.asc, g.desc],
1865
- default: g.asc,
1866
- type: "string"
1867
- },
1868
- groups: {
1869
- type: "array",
1870
- default: []
1871
- }
1872
- },
1873
- additionalProperties: !1
1874
- }
1875
- ],
1876
- messages: {
1877
- unexpectedClassesOrder: 'Expected "{{right}}" to come before "{{left}}"'
1878
- }
1879
- },
1880
- defaultOptions: [
1881
- {
1882
- type: u.alphabetical,
1883
- order: g.asc
1884
- }
1885
- ],
1886
- create: (e) => ({
1887
- ClassBody: (i) => {
1888
- if (i.body.length > 1) {
1889
- let s = j(e.options.at(0), {
1890
- type: u.alphabetical,
1891
- order: g.asc,
1892
- "ignore-case": !1,
1893
- groups: ["property", "constructor", "method", "unknown"]
1894
- }), l = i.body.map((r) => {
1895
- var f;
1896
- let t, { getGroup: a, defineGroup: n } = G(s.groups);
1897
- r.type === "StaticBlock" ? t = "static" : r.type === "TSIndexSignature" ? t = e.sourceCode.text.slice(
1898
- r.range.at(0),
1899
- ((f = r.typeAnnotation) == null ? void 0 : f.range.at(0)) ?? r.range.at(1)
1900
- ) : r.key.type === "Identifier" ? { name: t } = r.key : t = e.sourceCode.text.slice(...r.key.range);
1901
- let o = t.startsWith("_") || t.startsWith("#"), p = "decorators" in r && r.decorators.length > 0;
1902
- if (r.type === "MethodDefinition") {
1903
- r.kind === "constructor" && n("constructor");
1904
- let y = r.accessibility === "private" || o, d = r.static;
1905
- p && (r.kind === "get" && n("decorated-get-method"), r.kind === "set" && n("decorated-set-method"), n("decorated-method")), y && d && n("static-private-method"), y && n("private-method"), d && n("static-method"), r.kind === "get" && n("get-method"), r.kind === "set" && n("set-method"), n("method");
1906
- } else
1907
- r.type === "TSIndexSignature" ? n("index-signature") : r.type === "AccessorProperty" ? p && ((r.accessibility === "private" || o) && n("private-decorated-accessor-property"), n("decorated-accessor-property")) : r.type === "PropertyDefinition" && (p && ((r.accessibility === "private" || o) && n("private-decorated-property"), n("decorated-property")), (r.accessibility === "private" || o) && n("private-property"), r.static && n("static-property"), n("property"));
1908
- return {
1909
- size: I(r.range),
1910
- group: a(),
1911
- node: r,
1912
- name: t
1913
- };
1914
- });
1915
- P(l, (r, t) => {
1916
- let a = h(s.groups, r), n = h(s.groups, t);
1917
- r.name !== t.name && (a > n || a === n && O(S(r, t, s))) && e.report({
1918
- messageId: "unexpectedClassesOrder",
1919
- data: {
1920
- left: k(r.name),
1921
- right: k(t.name)
1922
- },
1923
- node: t.node,
1924
- fix: (o) => {
1925
- let p = [], f = l.reduce(
1926
- (d, c) => {
1927
- let m = h(s.groups, c);
1928
- return m in d ? d[m] = v(
1929
- [...d[m], c],
1930
- s
1931
- ) : d[m] = [c], d;
1932
- },
1933
- {}
1934
- ), y = Object.keys(f).sort((d, c) => Number(d) - Number(c)).reduce(
1935
- (d, c) => [
1936
- ...d,
1937
- ...f[c]
1938
- ],
1939
- []
1940
- );
1941
- for (let d = 0, c = y.length; d < c; d++)
1942
- p.push(
1943
- o.replaceTextRange(
1944
- T(l.at(d).node, e.sourceCode),
1945
- e.sourceCode.text.slice(
1946
- ...T(
1947
- y.at(d).node,
1948
- e.sourceCode
1949
- )
1950
- )
1951
- )
1952
- );
1953
- return p;
1954
- }
1955
- });
1956
- });
1957
- }
1958
- }
1959
- })
1960
- }), ie = "sort-enums", Oe = A({
1961
- name: ie,
1962
- meta: {
1963
- type: "suggestion",
1964
- docs: {
1965
- description: "enforce sorted TypeScript enums"
1966
- },
1967
- fixable: "code",
1968
- schema: [
1969
- {
1970
- type: "object",
1971
- properties: {
1972
- "partition-by-comment": {
1973
- default: !1,
1974
- type: ["boolean", "string", "array"]
1975
- },
1976
- type: {
1977
- enum: [
1978
- u.alphabetical,
1979
- u.natural,
1980
- u["line-length"]
1981
- ],
1982
- default: u.alphabetical,
1983
- type: "string"
1984
- },
1985
- "ignore-case": {
1986
- type: "boolean",
1987
- default: !1
1988
- },
1989
- order: {
1990
- enum: [g.asc, g.desc],
1991
- default: g.asc,
1992
- type: "string"
1993
- }
1994
- },
1995
- additionalProperties: !1
1996
- }
1997
- ],
1998
- messages: {
1999
- unexpectedEnumsOrder: 'Expected "{{right}}" to come before "{{left}}"'
2000
- }
2001
- },
2002
- defaultOptions: [
2003
- {
2004
- type: u.alphabetical,
2005
- order: g.asc
2006
- }
2007
- ],
2008
- create: (e) => ({
2009
- TSEnumDeclaration: (i) => {
2010
- if (i.members.length > 1 && i.members.every(({ initializer: s }) => s)) {
2011
- let s = j(e.options.at(0), {
2012
- type: u.alphabetical,
2013
- order: g.asc,
2014
- "ignore-case": !1,
2015
- "partition-by-comment": !1
2016
- }), l = s["partition-by-comment"], r = i.members.reduce(
2017
- (t, a) => {
2018
- let n = V(a, e.sourceCode);
2019
- l && n && X(l, n.value) && t.push([]);
2020
- let p = {
2021
- name: a.id.type === "Literal" ? `${a.id.value}` : `${e.sourceCode.text.slice(...a.id.range)}`,
2022
- node: a,
2023
- size: I(a.range)
2024
- };
2025
- return t.at(-1).push(p), t;
2026
- },
2027
- [[]]
2028
- );
2029
- for (let t of r)
2030
- P(t, (a, n) => {
2031
- O(S(a, n, s)) && e.report({
2032
- messageId: "unexpectedEnumsOrder",
2033
- data: {
2034
- left: k(a.name),
2035
- right: k(n.name)
2036
- },
2037
- node: n.node,
2038
- fix: (o) => M(
2039
- o,
2040
- t,
2041
- v(t, s),
2042
- e.sourceCode,
2043
- { partitionComment: l }
2044
- )
2045
- });
2046
- });
2047
- }
2048
- }
2049
- })
2050
- }), pe = "sort-maps", je = A({
2051
- name: pe,
2052
- meta: {
2053
- type: "suggestion",
2054
- docs: {
2055
- description: "enforce sorted Map elements"
2056
- },
2057
- fixable: "code",
2058
- schema: [
2059
- {
2060
- type: "object",
2061
- properties: {
2062
- type: {
2063
- enum: [
2064
- u.alphabetical,
2065
- u.natural,
2066
- u["line-length"]
2067
- ],
2068
- default: u.alphabetical,
2069
- type: "string"
2070
- },
2071
- order: {
2072
- enum: [g.asc, g.desc],
2073
- default: g.asc,
2074
- type: "string"
2075
- },
2076
- "ignore-case": {
2077
- type: "boolean",
2078
- default: !1
2079
- }
2080
- },
2081
- additionalProperties: !1
2082
- }
2083
- ],
2084
- messages: {
2085
- unexpectedMapElementsOrder: 'Expected "{{right}}" to come before "{{left}}"'
2086
- }
2087
- },
2088
- defaultOptions: [
2089
- {
2090
- type: u.alphabetical,
2091
- order: g.asc
2092
- }
2093
- ],
2094
- create: (e) => ({
2095
- NewExpression: (i) => {
2096
- if (i.callee.type === "Identifier" && i.callee.name === "Map" && i.arguments.length && i.arguments[0].type === "ArrayExpression") {
2097
- let [{ elements: s }] = i.arguments;
2098
- if (s.length > 1) {
2099
- let l = j(e.options.at(0), {
2100
- type: u.alphabetical,
2101
- "ignore-case": !1,
2102
- order: g.asc
2103
- }), r = s.reduce(
2104
- (t, a) => (a === null || a.type === "SpreadElement" ? t.push([]) : t.at(-1).push(a), t),
2105
- [[]]
2106
- );
2107
- for (let t of r) {
2108
- let a = t.map((n) => {
2109
- let o;
2110
- if (n.type === "ArrayExpression") {
2111
- let [p] = n.elements;
2112
- p ? p.type === "Literal" ? o = p.raw : o = e.sourceCode.text.slice(...p.range) : o = `${p}`;
2113
- } else
2114
- o = e.sourceCode.text.slice(...n.range);
2115
- return {
2116
- size: I(n.range),
2117
- node: n,
2118
- name: o
2119
- };
2120
- });
2121
- P(a, (n, o) => {
2122
- O(S(n, o, l)) && e.report({
2123
- messageId: "unexpectedMapElementsOrder",
2124
- data: {
2125
- left: k(n.name),
2126
- right: k(o.name)
2127
- },
2128
- node: o.node,
2129
- fix: (p) => M(
2130
- p,
2131
- a,
2132
- v(a, l),
2133
- e.sourceCode
2134
- )
2135
- });
2136
- });
2137
- }
2138
- }
2139
- }
2140
- }
2141
- })
2142
- }), Pe = "eslint-plugin-perfectionist";
2143
- let J = (e) => {
2144
- let i = {
2145
- [oe]: [
1
+ import sortIntersectionTypes, { RULE_NAME as RULE_NAME$e } from "./rules/sort-intersection-types.mjs";
2
+ import sortSvelteAttributes, { RULE_NAME as RULE_NAME$d } from "./rules/sort-svelte-attributes.mjs";
3
+ import sortAstroAttributes, { RULE_NAME as RULE_NAME$1 } from "./rules/sort-astro-attributes.mjs";
4
+ import sortArrayIncludes, { RULE_NAME } from "./rules/sort-array-includes.mjs";
5
+ import sortVueAttributes, { RULE_NAME as RULE_NAME$g } from "./rules/sort-vue-attributes.mjs";
6
+ import sortNamedExports, { RULE_NAME as RULE_NAME$9 } from "./rules/sort-named-exports.mjs";
7
+ import sortNamedImports, { RULE_NAME as RULE_NAME$a } from "./rules/sort-named-imports.mjs";
8
+ import sortObjectTypes, { RULE_NAME as RULE_NAME$b } from "./rules/sort-object-types.mjs";
9
+ import sortUnionTypes, { RULE_NAME as RULE_NAME$f } from "./rules/sort-union-types.mjs";
10
+ import sortInterfaces, { RULE_NAME as RULE_NAME$6 } from "./rules/sort-interfaces.mjs";
11
+ import sortJsxProps, { RULE_NAME as RULE_NAME$7 } from "./rules/sort-jsx-props.mjs";
12
+ import sortExports, { RULE_NAME as RULE_NAME$4 } from "./rules/sort-exports.mjs";
13
+ import sortImports, { RULE_NAME as RULE_NAME$5 } from "./rules/sort-imports.mjs";
14
+ import sortObjects, { RULE_NAME as RULE_NAME$c } from "./rules/sort-objects.mjs";
15
+ import sortClasses, { RULE_NAME as RULE_NAME$2 } from "./rules/sort-classes.mjs";
16
+ import sortEnums, { RULE_NAME as RULE_NAME$3 } from "./rules/sort-enums.mjs";
17
+ import sortMaps, { RULE_NAME as RULE_NAME$8 } from "./rules/sort-maps.mjs";
18
+ import { SortType, SortOrder } from "./typings/index.mjs";
19
+ import { name } from "./package.json.mjs";
20
+ let createConfigWithOptions = (options) => {
21
+ let recommendedRules = {
22
+ [RULE_NAME$5]: [
2146
23
  "error",
2147
24
  {
2148
25
  groups: [
@@ -2163,7 +40,7 @@ let J = (e) => {
2163
40
  "internal-pattern": ["~/**"]
2164
41
  }
2165
42
  ],
2166
- [le]: [
43
+ [RULE_NAME$2]: [
2167
44
  "error",
2168
45
  {
2169
46
  groups: [
@@ -2180,78 +57,80 @@ let J = (e) => {
2180
57
  ]
2181
58
  }
2182
59
  ],
2183
- [ne]: [
60
+ [RULE_NAME$c]: [
2184
61
  "error",
2185
62
  {
2186
- "partition-by-comment": !1
63
+ "partition-by-comment": false
2187
64
  }
2188
65
  ],
2189
- [Q]: [
66
+ [RULE_NAME]: [
2190
67
  "error",
2191
68
  {
2192
- "spread-last": !0
2193
- }
2194
- ],
2195
- [q]: ["error"],
2196
- [H]: ["error"],
2197
- [Y]: ["error"],
2198
- [Z]: ["error"],
2199
- [F]: ["error"],
2200
- [ee]: ["error"],
2201
- [te]: ["error"],
2202
- [re]: ["error"],
2203
- [se]: ["error"],
2204
- [ae]: ["error"],
2205
- [ie]: ["error"],
2206
- [pe]: ["error"]
69
+ "spread-last": true
70
+ }
71
+ ],
72
+ [RULE_NAME$e]: ["error"],
73
+ [RULE_NAME$d]: ["error"],
74
+ [RULE_NAME$1]: ["error"],
75
+ [RULE_NAME$g]: ["error"],
76
+ [RULE_NAME$9]: ["error"],
77
+ [RULE_NAME$a]: ["error"],
78
+ [RULE_NAME$b]: ["error"],
79
+ [RULE_NAME$f]: ["error"],
80
+ [RULE_NAME$6]: ["error"],
81
+ [RULE_NAME$7]: ["error"],
82
+ [RULE_NAME$4]: ["error"],
83
+ [RULE_NAME$3]: ["error"],
84
+ [RULE_NAME$8]: ["error"]
2207
85
  };
2208
86
  return {
2209
87
  rules: Object.fromEntries(
2210
- Object.entries(i).map(([s, [l, r = {}]]) => [
2211
- `perfectionist/${s}`,
2212
- [l, Object.assign(r, e)]
88
+ Object.entries(recommendedRules).map(([key, [message, baseOptions = {}]]) => [
89
+ `perfectionist/${key}`,
90
+ [message, Object.assign(baseOptions, options)]
2213
91
  ])
2214
92
  ),
2215
93
  plugins: ["perfectionist"]
2216
94
  };
2217
95
  };
2218
- const De = {
96
+ const mod = {
2219
97
  rules: {
2220
- [Q]: he,
2221
- [H]: me,
2222
- [le]: Ie,
2223
- [ie]: Oe,
2224
- [ae]: Se,
2225
- [oe]: ke,
2226
- [re]: ve,
2227
- [se]: we,
2228
- [pe]: je,
2229
- [Z]: xe,
2230
- [F]: Ee,
2231
- [ee]: Ne,
2232
- [ne]: Ae,
2233
- [q]: ye,
2234
- [te]: Ce,
2235
- [Y]: be
98
+ [RULE_NAME]: sortArrayIncludes,
99
+ [RULE_NAME$1]: sortAstroAttributes,
100
+ [RULE_NAME$2]: sortClasses,
101
+ [RULE_NAME$3]: sortEnums,
102
+ [RULE_NAME$4]: sortExports,
103
+ [RULE_NAME$5]: sortImports,
104
+ [RULE_NAME$6]: sortInterfaces,
105
+ [RULE_NAME$7]: sortJsxProps,
106
+ [RULE_NAME$8]: sortMaps,
107
+ [RULE_NAME$9]: sortNamedExports,
108
+ [RULE_NAME$a]: sortNamedImports,
109
+ [RULE_NAME$b]: sortObjectTypes,
110
+ [RULE_NAME$c]: sortObjects,
111
+ [RULE_NAME$d]: sortSvelteAttributes,
112
+ [RULE_NAME$e]: sortIntersectionTypes,
113
+ [RULE_NAME$f]: sortUnionTypes,
114
+ [RULE_NAME$g]: sortVueAttributes
2236
115
  },
2237
116
  configs: {
2238
- "recommended-alphabetical": J({
2239
- type: u.alphabetical,
2240
- order: g.asc,
2241
- "ignore-case": !1
117
+ "recommended-alphabetical": createConfigWithOptions({
118
+ type: SortType.alphabetical,
119
+ order: SortOrder.asc,
120
+ "ignore-case": false
2242
121
  }),
2243
- "recommended-natural": J({
2244
- type: u.natural,
2245
- order: g.asc,
2246
- "ignore-case": !1
122
+ "recommended-natural": createConfigWithOptions({
123
+ type: SortType.natural,
124
+ order: SortOrder.asc,
125
+ "ignore-case": false
2247
126
  }),
2248
- "recommended-line-length": J({
2249
- type: u["line-length"],
2250
- order: g.desc
127
+ "recommended-line-length": createConfigWithOptions({
128
+ type: SortType["line-length"],
129
+ order: SortOrder.desc
2251
130
  })
2252
131
  },
2253
- name: Pe
132
+ name
2254
133
  };
2255
134
  export {
2256
- De as default
135
+ mod as default
2257
136
  };