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