eslint-plugin-perfectionist 2.7.0 → 2.8.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 +1 -1
- package/dist/configs/recommended-alphabetical.mjs +6 -5
- package/dist/configs/recommended-line-length.js +1 -1
- package/dist/configs/recommended-line-length.mjs +3 -2
- package/dist/configs/recommended-natural.js +1 -1
- package/dist/configs/recommended-natural.mjs +3 -2
- package/dist/index.js +3 -3
- package/dist/index.mjs +843 -796
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,139 +1,140 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ESLintUtils as
|
|
3
|
-
import { minimatch as
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import q from "node:path";
|
|
2
|
+
import { ESLintUtils as ge, ASTUtils as J } from "@typescript-eslint/utils";
|
|
3
|
+
import { minimatch as U } from "minimatch";
|
|
4
|
+
import ye from "natural-compare-lite";
|
|
5
|
+
import { AST_NODE_TYPES as fe } from "@typescript-eslint/types";
|
|
6
|
+
import { builtinModules as me } from "node:module";
|
|
7
|
+
let A = ge.RuleCreator(
|
|
7
8
|
(e) => `https://eslint-plugin-perfectionist.azat.io/rules/${e}`
|
|
8
|
-
),
|
|
9
|
-
for (let
|
|
10
|
-
let
|
|
11
|
-
if (i.group ===
|
|
12
|
-
return
|
|
9
|
+
), E = (e, i) => {
|
|
10
|
+
for (let a = 0, l = e.length; a < l; a++) {
|
|
11
|
+
let s = e[a];
|
|
12
|
+
if (i.group === s || Array.isArray(s) && typeof i.group == "string" && s.includes(i.group))
|
|
13
|
+
return a;
|
|
13
14
|
}
|
|
14
15
|
return e.length;
|
|
15
16
|
}, I = (e) => {
|
|
16
|
-
let [i,
|
|
17
|
-
return
|
|
17
|
+
let [i, a] = e;
|
|
18
|
+
return a - i;
|
|
18
19
|
}, O = (e) => e > 0;
|
|
19
|
-
var u = /* @__PURE__ */ ((e) => (e.alphabetical = "alphabetical", e["line-length"] = "line-length", e.natural = "natural", e))(u || {}),
|
|
20
|
-
let
|
|
21
|
-
let i,
|
|
22
|
-
!i && e.flat().includes(
|
|
20
|
+
var u = /* @__PURE__ */ ((e) => (e.alphabetical = "alphabetical", e["line-length"] = "line-length", e.natural = "natural", e))(u || {}), m = /* @__PURE__ */ ((e) => (e.desc = "desc", e.asc = "asc", e))(m || {}), T = /* @__PURE__ */ ((e) => (e["values-first"] = "values-first", e["types-first"] = "types-first", e.mixed = "mixed", e))(T || {}), G = /* @__PURE__ */ ((e) => (e["optional-first"] = "optional-first", e["required-first"] = "required-first", e.ignore = "ignore", e))(G || {});
|
|
21
|
+
let R = (e) => {
|
|
22
|
+
let i, a = (s) => {
|
|
23
|
+
!i && e.flat().includes(s) && (i = s);
|
|
23
24
|
};
|
|
24
25
|
return {
|
|
25
26
|
getGroup: () => i ?? "unknown",
|
|
26
|
-
setCustomGroups: (
|
|
27
|
-
if (
|
|
28
|
-
for (let [
|
|
29
|
-
Array.isArray(
|
|
30
|
-
(
|
|
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, {
|
|
31
32
|
nocomment: !0
|
|
32
33
|
})
|
|
33
|
-
) &&
|
|
34
|
+
) && a(n), typeof p == "string" && U(r, p, {
|
|
34
35
|
nocomment: !0
|
|
35
|
-
}) &&
|
|
36
|
+
}) && a(n);
|
|
36
37
|
},
|
|
37
|
-
defineGroup:
|
|
38
|
+
defineGroup: a
|
|
38
39
|
};
|
|
39
|
-
},
|
|
40
|
-
var
|
|
41
|
-
if ((
|
|
40
|
+
}, w = (e, i, a) => {
|
|
41
|
+
var n, p;
|
|
42
|
+
if ((n = i.dependencies) != null && n.includes(e.name))
|
|
42
43
|
return -1;
|
|
43
|
-
if ((
|
|
44
|
+
if ((p = e.dependencies) != null && p.includes(i.name))
|
|
44
45
|
return 1;
|
|
45
|
-
let l =
|
|
46
|
-
return
|
|
47
|
-
let f =
|
|
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"];
|
|
48
49
|
if (d) {
|
|
49
|
-
let
|
|
50
|
-
|
|
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);
|
|
51
52
|
}
|
|
52
|
-
return f -
|
|
53
|
-
}, l *
|
|
54
|
-
}, v = (e, i) => [...e].sort((
|
|
55
|
-
let
|
|
56
|
-
filter: ({ value: l, type:
|
|
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)),
|
|
57
58
|
includeComments: !0
|
|
58
59
|
});
|
|
59
|
-
return ((
|
|
60
|
-
},
|
|
61
|
-
(
|
|
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, {
|
|
62
63
|
nocomment: !0
|
|
63
64
|
})
|
|
64
|
-
) || typeof e == "string" &&
|
|
65
|
+
) || typeof e == "string" && U(i.trim(), e, {
|
|
65
66
|
nocomment: !0
|
|
66
|
-
}) || e === !0,
|
|
67
|
-
let [
|
|
68
|
-
filter: ({ value:
|
|
67
|
+
}) || e === !0, K = (e, i) => {
|
|
68
|
+
let [a, l] = i.getTokensBefore(e, {
|
|
69
|
+
filter: ({ value: s, type: r }) => !(r === "Punctuator" && [",", ";"].includes(s)),
|
|
69
70
|
includeComments: !0,
|
|
70
71
|
count: 2
|
|
71
72
|
});
|
|
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 && (
|
|
73
|
-
},
|
|
74
|
-
var
|
|
75
|
-
let l = e.range.at(0),
|
|
76
|
-
if (
|
|
77
|
-
let
|
|
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(
|
|
78
79
|
e,
|
|
79
|
-
|
|
80
|
-
),
|
|
80
|
+
J.isOpeningParenToken
|
|
81
|
+
), o = i.getTokenAfter(
|
|
81
82
|
e,
|
|
82
|
-
|
|
83
|
+
J.isClosingParenToken
|
|
83
84
|
);
|
|
84
|
-
l =
|
|
85
|
+
l = t.range.at(0), s = o.range.at(1);
|
|
85
86
|
}
|
|
86
|
-
let
|
|
87
|
-
if (
|
|
88
|
-
let
|
|
87
|
+
let n = K(e, i);
|
|
88
|
+
if (r.endsWith(";") || r.endsWith(",")) {
|
|
89
|
+
let t = i.getTokensAfter(e, {
|
|
89
90
|
includeComments: !0,
|
|
90
91
|
count: 2
|
|
91
92
|
});
|
|
92
|
-
e.loc.start.line === ((
|
|
93
|
+
e.loc.start.line === ((p = t.at(1)) == null ? void 0 : p.loc.start.line) && (s -= 1);
|
|
93
94
|
}
|
|
94
|
-
return
|
|
95
|
-
(
|
|
96
|
-
|
|
97
|
-
) && (l =
|
|
98
|
-
}, M = (e, i,
|
|
99
|
-
var
|
|
100
|
-
let
|
|
101
|
-
for (let
|
|
102
|
-
let { node:
|
|
103
|
-
|
|
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(
|
|
104
105
|
e.replaceTextRange(
|
|
105
|
-
|
|
106
|
+
L(c, l, s),
|
|
106
107
|
l.text.slice(
|
|
107
|
-
...
|
|
108
|
+
...L(a.at(o).node, l, s)
|
|
108
109
|
)
|
|
109
110
|
)
|
|
110
111
|
);
|
|
111
|
-
let d =
|
|
112
|
-
if (d && !
|
|
113
|
-
let
|
|
112
|
+
let d = he(a.at(o).node, l);
|
|
113
|
+
if (d && !n) {
|
|
114
|
+
let y = [
|
|
114
115
|
l.getTokenBefore(d).range.at(1),
|
|
115
116
|
d.range.at(1)
|
|
116
117
|
];
|
|
117
|
-
|
|
118
|
-
let
|
|
119
|
-
|
|
118
|
+
r.push(e.replaceTextRange(y, ""));
|
|
119
|
+
let b = l.getTokenAfter(c);
|
|
120
|
+
r.push(
|
|
120
121
|
e.insertTextAfter(
|
|
121
|
-
(
|
|
122
|
-
l.text.slice(...
|
|
122
|
+
(b == null ? void 0 : b.loc.end.line) === c.loc.end.line ? b : c,
|
|
123
|
+
l.text.slice(...y)
|
|
123
124
|
)
|
|
124
125
|
);
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
|
-
return
|
|
128
|
+
return r;
|
|
128
129
|
}, j = (e = {}, i) => Object.assign(i, e), P = (e, i) => {
|
|
129
130
|
if (e.length > 1)
|
|
130
|
-
for (let
|
|
131
|
-
let l = e.at(
|
|
132
|
-
l &&
|
|
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);
|
|
133
134
|
}
|
|
134
135
|
};
|
|
135
|
-
const
|
|
136
|
-
name:
|
|
136
|
+
const H = "sort-svelte-attributes", be = A({
|
|
137
|
+
name: H,
|
|
137
138
|
meta: {
|
|
138
139
|
type: "suggestion",
|
|
139
140
|
docs: {
|
|
@@ -157,8 +158,8 @@ const q = "sort-svelte-attributes", ye = A({
|
|
|
157
158
|
type: "string"
|
|
158
159
|
},
|
|
159
160
|
order: {
|
|
160
|
-
enum: [
|
|
161
|
-
default:
|
|
161
|
+
enum: [m.asc, m.desc],
|
|
162
|
+
default: m.asc,
|
|
162
163
|
type: "string"
|
|
163
164
|
},
|
|
164
165
|
"ignore-case": {
|
|
@@ -179,62 +180,62 @@ const q = "sort-svelte-attributes", ye = A({
|
|
|
179
180
|
defaultOptions: [
|
|
180
181
|
{
|
|
181
182
|
type: u.alphabetical,
|
|
182
|
-
order:
|
|
183
|
+
order: m.asc
|
|
183
184
|
}
|
|
184
185
|
],
|
|
185
|
-
create: (e) =>
|
|
186
|
+
create: (e) => q.extname(e.filename) !== ".svelte" ? {} : {
|
|
186
187
|
SvelteStartTag: (i) => {
|
|
187
188
|
if (i.attributes.length > 1) {
|
|
188
|
-
let
|
|
189
|
+
let a = j(e.options.at(0), {
|
|
189
190
|
type: u.alphabetical,
|
|
190
|
-
order:
|
|
191
|
+
order: m.asc,
|
|
191
192
|
"ignore-case": !1,
|
|
192
193
|
"custom-groups": {},
|
|
193
194
|
groups: []
|
|
194
195
|
}), l = i.attributes.reduce(
|
|
195
|
-
(
|
|
196
|
-
if (
|
|
197
|
-
return
|
|
198
|
-
let
|
|
199
|
-
|
|
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
|
|
200
201
|
);
|
|
201
|
-
return
|
|
202
|
-
size: I(
|
|
203
|
-
node:
|
|
204
|
-
group:
|
|
205
|
-
name:
|
|
206
|
-
}),
|
|
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;
|
|
207
208
|
},
|
|
208
209
|
[[]]
|
|
209
210
|
);
|
|
210
|
-
for (let
|
|
211
|
-
P(
|
|
212
|
-
let
|
|
213
|
-
(
|
|
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({
|
|
214
215
|
messageId: "unexpectedSvelteAttributesOrder",
|
|
215
216
|
data: {
|
|
216
|
-
left:
|
|
217
|
-
right:
|
|
217
|
+
left: r.name,
|
|
218
|
+
right: n.name
|
|
218
219
|
},
|
|
219
|
-
node:
|
|
220
|
-
fix: (
|
|
220
|
+
node: n.node,
|
|
221
|
+
fix: (o) => {
|
|
221
222
|
let f = {};
|
|
222
|
-
for (let d of
|
|
223
|
-
let
|
|
224
|
-
|
|
225
|
-
[...f[
|
|
226
|
-
|
|
227
|
-
) : 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];
|
|
228
229
|
}
|
|
229
|
-
let
|
|
230
|
+
let c = [];
|
|
230
231
|
for (let d of Object.keys(f).sort(
|
|
231
|
-
(
|
|
232
|
+
(g, y) => Number(g) - Number(y)
|
|
232
233
|
))
|
|
233
|
-
|
|
234
|
+
c.push(...v(f[d], a));
|
|
234
235
|
return M(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
o,
|
|
237
|
+
s,
|
|
238
|
+
c,
|
|
238
239
|
e.sourceCode
|
|
239
240
|
);
|
|
240
241
|
}
|
|
@@ -243,8 +244,8 @@ const q = "sort-svelte-attributes", ye = A({
|
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
}
|
|
246
|
-
}),
|
|
247
|
-
name:
|
|
247
|
+
}), Q = "sort-astro-attributes", xe = A({
|
|
248
|
+
name: Q,
|
|
248
249
|
meta: {
|
|
249
250
|
type: "suggestion",
|
|
250
251
|
docs: {
|
|
@@ -268,8 +269,8 @@ const q = "sort-svelte-attributes", ye = A({
|
|
|
268
269
|
type: "string"
|
|
269
270
|
},
|
|
270
271
|
order: {
|
|
271
|
-
enum: [
|
|
272
|
-
default:
|
|
272
|
+
enum: [m.asc, m.desc],
|
|
273
|
+
default: m.asc,
|
|
273
274
|
type: "string"
|
|
274
275
|
},
|
|
275
276
|
"ignore-case": {
|
|
@@ -290,63 +291,63 @@ const q = "sort-svelte-attributes", ye = A({
|
|
|
290
291
|
defaultOptions: [
|
|
291
292
|
{
|
|
292
293
|
type: u.alphabetical,
|
|
293
|
-
order:
|
|
294
|
+
order: m.asc
|
|
294
295
|
}
|
|
295
296
|
],
|
|
296
297
|
// @ts-ignore
|
|
297
|
-
create: (e) =>
|
|
298
|
+
create: (e) => q.extname(e.filename) !== ".astro" ? {} : {
|
|
298
299
|
JSXElement: (i) => {
|
|
299
|
-
let { attributes:
|
|
300
|
-
if (
|
|
300
|
+
let { attributes: a } = i.openingElement;
|
|
301
|
+
if (a.length > 1) {
|
|
301
302
|
let l = j(e.options.at(0), {
|
|
302
303
|
type: u.alphabetical,
|
|
303
|
-
order:
|
|
304
|
+
order: m.asc,
|
|
304
305
|
"ignore-case": !1,
|
|
305
306
|
"custom-groups": {},
|
|
306
307
|
groups: []
|
|
307
|
-
}),
|
|
308
|
-
(
|
|
309
|
-
if (
|
|
310
|
-
return
|
|
311
|
-
let
|
|
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(
|
|
312
313
|
l.groups
|
|
313
314
|
);
|
|
314
|
-
return f(l["custom-groups"],
|
|
315
|
-
size: I(
|
|
316
|
-
node:
|
|
317
|
-
group:
|
|
318
|
-
name:
|
|
319
|
-
}),
|
|
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;
|
|
320
321
|
},
|
|
321
322
|
[[]]
|
|
322
323
|
);
|
|
323
|
-
for (let
|
|
324
|
-
P(
|
|
325
|
-
let
|
|
326
|
-
(
|
|
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({
|
|
327
328
|
messageId: "unexpectedAstroAttributesOrder",
|
|
328
329
|
data: {
|
|
329
|
-
left:
|
|
330
|
-
right:
|
|
330
|
+
left: n.name,
|
|
331
|
+
right: p.name
|
|
331
332
|
},
|
|
332
|
-
node:
|
|
333
|
+
node: p.node,
|
|
333
334
|
fix: (f) => {
|
|
334
|
-
let
|
|
335
|
-
for (let
|
|
336
|
-
let
|
|
337
|
-
|
|
338
|
-
[...y
|
|
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],
|
|
339
340
|
l
|
|
340
|
-
) : y
|
|
341
|
+
) : c[y] = [g];
|
|
341
342
|
}
|
|
342
343
|
let d = [];
|
|
343
|
-
for (let
|
|
344
|
-
(
|
|
344
|
+
for (let g of Object.keys(c).sort(
|
|
345
|
+
(y, b) => Number(y) - Number(b)
|
|
345
346
|
))
|
|
346
|
-
d.push(...v(
|
|
347
|
+
d.push(...v(c[g], l));
|
|
347
348
|
return M(
|
|
348
349
|
f,
|
|
349
|
-
|
|
350
|
+
r,
|
|
350
351
|
d,
|
|
351
352
|
e.sourceCode
|
|
352
353
|
);
|
|
@@ -358,8 +359,8 @@ const q = "sort-svelte-attributes", ye = A({
|
|
|
358
359
|
}
|
|
359
360
|
});
|
|
360
361
|
let k = (e) => e.replaceAll(/\s\s+/g, " ").trim();
|
|
361
|
-
const
|
|
362
|
-
name:
|
|
362
|
+
const Z = "sort-array-includes", Ee = A({
|
|
363
|
+
name: Z,
|
|
363
364
|
meta: {
|
|
364
365
|
type: "suggestion",
|
|
365
366
|
docs: {
|
|
@@ -380,8 +381,8 @@ const Q = "sort-array-includes", he = A({
|
|
|
380
381
|
type: "string"
|
|
381
382
|
},
|
|
382
383
|
order: {
|
|
383
|
-
enum: [
|
|
384
|
-
default:
|
|
384
|
+
enum: [m.asc, m.desc],
|
|
385
|
+
default: m.asc,
|
|
385
386
|
type: "string"
|
|
386
387
|
},
|
|
387
388
|
"ignore-case": {
|
|
@@ -403,46 +404,46 @@ const Q = "sort-array-includes", he = A({
|
|
|
403
404
|
defaultOptions: [
|
|
404
405
|
{
|
|
405
406
|
type: u.alphabetical,
|
|
406
|
-
order:
|
|
407
|
+
order: m.asc
|
|
407
408
|
}
|
|
408
409
|
],
|
|
409
410
|
create: (e) => ({
|
|
410
411
|
MemberExpression: (i) => {
|
|
411
412
|
if ((i.object.type === "ArrayExpression" || i.object.type === "NewExpression") && i.property.type === "Identifier" && i.property.name === "includes") {
|
|
412
|
-
let
|
|
413
|
-
if (
|
|
413
|
+
let a = i.object.type === "ArrayExpression" ? i.object.elements : i.object.arguments;
|
|
414
|
+
if (a.length > 1) {
|
|
414
415
|
let l = j(e.options.at(0), {
|
|
415
416
|
type: u.alphabetical,
|
|
416
|
-
order:
|
|
417
|
+
order: m.asc,
|
|
417
418
|
"ignore-case": !1,
|
|
418
419
|
"spread-last": !1
|
|
419
|
-
}),
|
|
420
|
-
(
|
|
421
|
-
name:
|
|
422
|
-
size: I(
|
|
423
|
-
type:
|
|
424
|
-
node:
|
|
425
|
-
}),
|
|
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),
|
|
426
427
|
[[], []]
|
|
427
428
|
).flat();
|
|
428
|
-
P(
|
|
429
|
-
let
|
|
430
|
-
l["spread-last"] &&
|
|
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({
|
|
431
432
|
messageId: "unexpectedArrayIncludesOrder",
|
|
432
433
|
data: {
|
|
433
|
-
left: k(
|
|
434
|
-
right: k(
|
|
434
|
+
left: k(r.name),
|
|
435
|
+
right: k(n.name)
|
|
435
436
|
},
|
|
436
|
-
node:
|
|
437
|
-
fix: (
|
|
438
|
-
let
|
|
437
|
+
node: n.node,
|
|
438
|
+
fix: (t) => {
|
|
439
|
+
let o = v(s, l);
|
|
439
440
|
if (l["spread-last"])
|
|
440
|
-
for (let f = 0,
|
|
441
|
-
|
|
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));
|
|
442
443
|
return M(
|
|
444
|
+
t,
|
|
445
|
+
s,
|
|
443
446
|
o,
|
|
444
|
-
r,
|
|
445
|
-
p,
|
|
446
447
|
e.sourceCode
|
|
447
448
|
);
|
|
448
449
|
}
|
|
@@ -452,8 +453,8 @@ const Q = "sort-array-includes", he = A({
|
|
|
452
453
|
}
|
|
453
454
|
}
|
|
454
455
|
})
|
|
455
|
-
}),
|
|
456
|
-
name:
|
|
456
|
+
}), F = "sort-vue-attributes", Ne = A({
|
|
457
|
+
name: F,
|
|
457
458
|
meta: {
|
|
458
459
|
type: "suggestion",
|
|
459
460
|
docs: {
|
|
@@ -477,8 +478,8 @@ const Q = "sort-array-includes", he = A({
|
|
|
477
478
|
type: "string"
|
|
478
479
|
},
|
|
479
480
|
order: {
|
|
480
|
-
enum: [
|
|
481
|
-
default:
|
|
481
|
+
enum: [m.asc, m.desc],
|
|
482
|
+
default: m.asc,
|
|
482
483
|
type: "string"
|
|
483
484
|
},
|
|
484
485
|
"ignore-case": {
|
|
@@ -500,67 +501,67 @@ const Q = "sort-array-includes", he = A({
|
|
|
500
501
|
defaultOptions: [
|
|
501
502
|
{
|
|
502
503
|
type: u.alphabetical,
|
|
503
|
-
order:
|
|
504
|
+
order: m.asc
|
|
504
505
|
}
|
|
505
506
|
],
|
|
506
507
|
create: (e) => {
|
|
507
|
-
if (
|
|
508
|
+
if (q.extname(e.filename) !== ".vue")
|
|
508
509
|
return {};
|
|
509
510
|
if (!("defineTemplateBodyVisitor" in e.sourceCode.parserServices))
|
|
510
511
|
return {};
|
|
511
512
|
let { defineTemplateBodyVisitor: i } = e.sourceCode.parserServices;
|
|
512
513
|
return i({
|
|
513
|
-
VStartTag: (
|
|
514
|
-
if (
|
|
514
|
+
VStartTag: (a) => {
|
|
515
|
+
if (a.attributes.length > 1) {
|
|
515
516
|
let l = j(e.options.at(0), {
|
|
516
517
|
type: u.alphabetical,
|
|
517
|
-
order:
|
|
518
|
+
order: m.asc,
|
|
518
519
|
"ignore-case": !1,
|
|
519
520
|
"custom-groups": {},
|
|
520
521
|
groups: []
|
|
521
|
-
}),
|
|
522
|
-
(
|
|
523
|
-
if (
|
|
524
|
-
return
|
|
525
|
-
let
|
|
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(
|
|
526
527
|
l.groups
|
|
527
528
|
);
|
|
528
|
-
return typeof
|
|
529
|
-
size: I(
|
|
530
|
-
node:
|
|
531
|
-
group:
|
|
532
|
-
name:
|
|
533
|
-
}),
|
|
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;
|
|
534
535
|
},
|
|
535
536
|
[[]]
|
|
536
537
|
);
|
|
537
|
-
for (let
|
|
538
|
-
P(
|
|
539
|
-
let
|
|
540
|
-
(
|
|
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({
|
|
541
542
|
messageId: "unexpectedVueAttributesOrder",
|
|
542
543
|
data: {
|
|
543
|
-
left:
|
|
544
|
-
right:
|
|
544
|
+
left: n.name,
|
|
545
|
+
right: p.name
|
|
545
546
|
},
|
|
546
|
-
node:
|
|
547
|
+
node: p.node,
|
|
547
548
|
fix: (f) => {
|
|
548
|
-
let
|
|
549
|
-
for (let
|
|
550
|
-
let
|
|
551
|
-
|
|
552
|
-
[...y
|
|
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],
|
|
553
554
|
l
|
|
554
|
-
) : y
|
|
555
|
+
) : c[y] = [g];
|
|
555
556
|
}
|
|
556
557
|
let d = [];
|
|
557
|
-
for (let
|
|
558
|
-
(
|
|
558
|
+
for (let g of Object.keys(c).sort(
|
|
559
|
+
(y, b) => Number(y) - Number(b)
|
|
559
560
|
))
|
|
560
|
-
d.push(...v(
|
|
561
|
+
d.push(...v(c[g], l));
|
|
561
562
|
return M(
|
|
562
563
|
f,
|
|
563
|
-
|
|
564
|
+
r,
|
|
564
565
|
d,
|
|
565
566
|
e.sourceCode
|
|
566
567
|
);
|
|
@@ -571,8 +572,8 @@ const Q = "sort-array-includes", he = A({
|
|
|
571
572
|
}
|
|
572
573
|
});
|
|
573
574
|
}
|
|
574
|
-
}),
|
|
575
|
-
name:
|
|
575
|
+
}), ee = "sort-named-exports", Ce = A({
|
|
576
|
+
name: ee,
|
|
576
577
|
meta: {
|
|
577
578
|
type: "suggestion",
|
|
578
579
|
docs: {
|
|
@@ -593,8 +594,8 @@ const Q = "sort-array-includes", he = A({
|
|
|
593
594
|
type: "string"
|
|
594
595
|
},
|
|
595
596
|
order: {
|
|
596
|
-
enum: [
|
|
597
|
-
default:
|
|
597
|
+
enum: [m.asc, m.desc],
|
|
598
|
+
default: m.asc,
|
|
598
599
|
type: "string"
|
|
599
600
|
},
|
|
600
601
|
"ignore-case": {
|
|
@@ -603,11 +604,11 @@ const Q = "sort-array-includes", he = A({
|
|
|
603
604
|
},
|
|
604
605
|
"group-kind": {
|
|
605
606
|
enum: [
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
607
|
+
T.mixed,
|
|
608
|
+
T["values-first"],
|
|
609
|
+
T["types-first"]
|
|
609
610
|
],
|
|
610
|
-
default:
|
|
611
|
+
default: T.mixed,
|
|
611
612
|
type: "string"
|
|
612
613
|
}
|
|
613
614
|
},
|
|
@@ -621,43 +622,43 @@ const Q = "sort-array-includes", he = A({
|
|
|
621
622
|
defaultOptions: [
|
|
622
623
|
{
|
|
623
624
|
type: u.alphabetical,
|
|
624
|
-
order:
|
|
625
|
+
order: m.asc
|
|
625
626
|
}
|
|
626
627
|
],
|
|
627
628
|
create: (e) => ({
|
|
628
629
|
ExportNamedDeclaration: (i) => {
|
|
629
630
|
if (i.specifiers.length > 1) {
|
|
630
|
-
let
|
|
631
|
+
let a = j(e.options.at(0), {
|
|
631
632
|
type: u.alphabetical,
|
|
632
633
|
"ignore-case": !1,
|
|
633
|
-
order:
|
|
634
|
-
"group-kind":
|
|
635
|
-
}), l = i.specifiers.map((
|
|
636
|
-
size: I(
|
|
637
|
-
name:
|
|
638
|
-
node:
|
|
639
|
-
group:
|
|
640
|
-
})),
|
|
641
|
-
P(l, (
|
|
642
|
-
let
|
|
643
|
-
if (
|
|
644
|
-
let f =
|
|
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);
|
|
645
646
|
e.report({
|
|
646
647
|
messageId: "unexpectedNamedExportsOrder",
|
|
647
648
|
data: {
|
|
648
|
-
left:
|
|
649
|
-
right:
|
|
649
|
+
left: n.name,
|
|
650
|
+
right: p.name
|
|
650
651
|
},
|
|
651
|
-
node:
|
|
652
|
-
fix: (
|
|
652
|
+
node: p.node,
|
|
653
|
+
fix: (c) => M(c, l, f, e.sourceCode)
|
|
653
654
|
});
|
|
654
655
|
}
|
|
655
656
|
});
|
|
656
657
|
}
|
|
657
658
|
}
|
|
658
659
|
})
|
|
659
|
-
}),
|
|
660
|
-
name:
|
|
660
|
+
}), te = "sort-named-imports", ve = A({
|
|
661
|
+
name: te,
|
|
661
662
|
meta: {
|
|
662
663
|
type: "suggestion",
|
|
663
664
|
docs: {
|
|
@@ -678,8 +679,8 @@ const Q = "sort-array-includes", he = A({
|
|
|
678
679
|
type: "string"
|
|
679
680
|
},
|
|
680
681
|
order: {
|
|
681
|
-
enum: [
|
|
682
|
-
default:
|
|
682
|
+
enum: [m.asc, m.desc],
|
|
683
|
+
default: m.asc,
|
|
683
684
|
type: "string"
|
|
684
685
|
},
|
|
685
686
|
"ignore-case": {
|
|
@@ -692,11 +693,11 @@ const Q = "sort-array-includes", he = A({
|
|
|
692
693
|
},
|
|
693
694
|
"group-kind": {
|
|
694
695
|
enum: [
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
696
|
+
T.mixed,
|
|
697
|
+
T["values-first"],
|
|
698
|
+
T["types-first"]
|
|
698
699
|
],
|
|
699
|
-
default:
|
|
700
|
+
default: T.mixed,
|
|
700
701
|
type: "string"
|
|
701
702
|
}
|
|
702
703
|
},
|
|
@@ -710,42 +711,42 @@ const Q = "sort-array-includes", he = A({
|
|
|
710
711
|
defaultOptions: [
|
|
711
712
|
{
|
|
712
713
|
type: u.alphabetical,
|
|
713
|
-
order:
|
|
714
|
+
order: m.asc
|
|
714
715
|
}
|
|
715
716
|
],
|
|
716
717
|
create: (e) => ({
|
|
717
718
|
ImportDeclaration: (i) => {
|
|
718
|
-
let
|
|
719
|
+
let a = i.specifiers.filter(
|
|
719
720
|
({ type: l }) => l === "ImportSpecifier"
|
|
720
721
|
);
|
|
721
|
-
if (
|
|
722
|
+
if (a.length > 1) {
|
|
722
723
|
let l = j(e.options.at(0), {
|
|
723
724
|
type: u.alphabetical,
|
|
724
725
|
"ignore-alias": !0,
|
|
725
726
|
"ignore-case": !1,
|
|
726
|
-
order:
|
|
727
|
-
"group-kind":
|
|
728
|
-
}),
|
|
729
|
-
let
|
|
730
|
-
return
|
|
731
|
-
size: I(
|
|
732
|
-
node:
|
|
733
|
-
name:
|
|
734
|
-
group:
|
|
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
|
|
735
736
|
};
|
|
736
|
-
}),
|
|
737
|
-
P(
|
|
738
|
-
let
|
|
739
|
-
if (
|
|
740
|
-
let
|
|
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);
|
|
741
742
|
e.report({
|
|
742
743
|
messageId: "unexpectedNamedImportsOrder",
|
|
743
744
|
data: {
|
|
744
|
-
left:
|
|
745
|
-
right:
|
|
745
|
+
left: p.name,
|
|
746
|
+
right: t.name
|
|
746
747
|
},
|
|
747
|
-
node:
|
|
748
|
-
fix: (d) => M(d,
|
|
748
|
+
node: t.node,
|
|
749
|
+
fix: (d) => M(d, s, c, e.sourceCode)
|
|
749
750
|
});
|
|
750
751
|
}
|
|
751
752
|
});
|
|
@@ -753,12 +754,12 @@ const Q = "sort-array-includes", he = A({
|
|
|
753
754
|
}
|
|
754
755
|
})
|
|
755
756
|
});
|
|
756
|
-
let
|
|
757
|
+
let W = (e, i, a) => e.lines.slice(
|
|
757
758
|
i.node.loc.end.line,
|
|
758
|
-
|
|
759
|
-
).filter((
|
|
760
|
-
const
|
|
761
|
-
name:
|
|
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,
|
|
762
763
|
meta: {
|
|
763
764
|
type: "suggestion",
|
|
764
765
|
docs: {
|
|
@@ -782,8 +783,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
782
783
|
type: "string"
|
|
783
784
|
},
|
|
784
785
|
order: {
|
|
785
|
-
enum: [
|
|
786
|
-
default:
|
|
786
|
+
enum: [m.asc, m.desc],
|
|
787
|
+
default: m.asc,
|
|
787
788
|
type: "string"
|
|
788
789
|
},
|
|
789
790
|
"ignore-case": {
|
|
@@ -809,86 +810,86 @@ const ee = "sort-object-types", Ne = A({
|
|
|
809
810
|
defaultOptions: [
|
|
810
811
|
{
|
|
811
812
|
type: u.alphabetical,
|
|
812
|
-
order:
|
|
813
|
+
order: m.asc
|
|
813
814
|
}
|
|
814
815
|
],
|
|
815
816
|
create: (e) => ({
|
|
816
817
|
TSTypeLiteral: (i) => {
|
|
817
818
|
if (i.members.length > 1) {
|
|
818
|
-
let
|
|
819
|
+
let a = j(e.options.at(0), {
|
|
819
820
|
"partition-by-new-line": !1,
|
|
820
821
|
type: u.alphabetical,
|
|
821
822
|
"ignore-case": !1,
|
|
822
|
-
order:
|
|
823
|
+
order: m.asc,
|
|
823
824
|
"custom-groups": {},
|
|
824
825
|
groups: []
|
|
825
826
|
}), l = i.members.reduce(
|
|
826
|
-
(
|
|
827
|
-
var C,
|
|
828
|
-
let
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
),
|
|
832
|
-
|
|
833
|
-
), d = (
|
|
834
|
-
if (
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
(
|
|
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)
|
|
838
839
|
);
|
|
839
|
-
else if (
|
|
840
|
-
let
|
|
841
|
-
|
|
842
|
-
e.sourceCode.text.slice(
|
|
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)
|
|
843
844
|
);
|
|
844
845
|
} else
|
|
845
|
-
|
|
846
|
+
n = d(
|
|
846
847
|
e.sourceCode.text.slice(
|
|
847
|
-
|
|
848
|
-
|
|
848
|
+
r.range.at(0),
|
|
849
|
+
r.range.at(1)
|
|
849
850
|
)
|
|
850
851
|
);
|
|
851
|
-
|
|
852
|
-
let
|
|
853
|
-
size: I(
|
|
854
|
-
node:
|
|
855
|
-
name:
|
|
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
|
|
856
857
|
};
|
|
857
|
-
return
|
|
858
|
-
...
|
|
859
|
-
group:
|
|
860
|
-
}),
|
|
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;
|
|
861
862
|
},
|
|
862
863
|
[[]]
|
|
863
864
|
);
|
|
864
|
-
for (let
|
|
865
|
-
P(
|
|
866
|
-
let
|
|
867
|
-
(
|
|
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({
|
|
868
869
|
messageId: "unexpectedObjectTypesOrder",
|
|
869
870
|
data: {
|
|
870
|
-
left: k(
|
|
871
|
-
right: k(
|
|
871
|
+
left: k(r.name),
|
|
872
|
+
right: k(n.name)
|
|
872
873
|
},
|
|
873
|
-
node:
|
|
874
|
-
fix: (
|
|
874
|
+
node: n.node,
|
|
875
|
+
fix: (o) => {
|
|
875
876
|
let f = {};
|
|
876
|
-
for (let d of
|
|
877
|
-
let
|
|
878
|
-
|
|
879
|
-
[...f[
|
|
880
|
-
|
|
881
|
-
) : 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];
|
|
882
883
|
}
|
|
883
|
-
let
|
|
884
|
+
let c = [];
|
|
884
885
|
for (let d of Object.keys(f).sort(
|
|
885
|
-
(
|
|
886
|
+
(g, y) => Number(g) - Number(y)
|
|
886
887
|
))
|
|
887
|
-
|
|
888
|
+
c.push(...v(f[d], a));
|
|
888
889
|
return M(
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
890
|
+
o,
|
|
891
|
+
s,
|
|
892
|
+
c,
|
|
892
893
|
e.sourceCode
|
|
893
894
|
);
|
|
894
895
|
}
|
|
@@ -897,8 +898,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
897
898
|
}
|
|
898
899
|
}
|
|
899
900
|
})
|
|
900
|
-
}),
|
|
901
|
-
name:
|
|
901
|
+
}), se = "sort-union-types", we = A({
|
|
902
|
+
name: se,
|
|
902
903
|
meta: {
|
|
903
904
|
type: "suggestion",
|
|
904
905
|
docs: {
|
|
@@ -919,8 +920,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
919
920
|
type: "string"
|
|
920
921
|
},
|
|
921
922
|
order: {
|
|
922
|
-
enum: [
|
|
923
|
-
default:
|
|
923
|
+
enum: [m.asc, m.desc],
|
|
924
|
+
default: m.asc,
|
|
924
925
|
type: "string"
|
|
925
926
|
},
|
|
926
927
|
"ignore-case": {
|
|
@@ -942,49 +943,58 @@ const ee = "sort-object-types", Ne = A({
|
|
|
942
943
|
defaultOptions: [
|
|
943
944
|
{
|
|
944
945
|
type: u.alphabetical,
|
|
945
|
-
order:
|
|
946
|
+
order: m.asc
|
|
946
947
|
}
|
|
947
948
|
],
|
|
948
949
|
create: (e) => ({
|
|
949
950
|
TSUnionType: (i) => {
|
|
950
|
-
let
|
|
951
|
+
let a = j(e.options.at(0), {
|
|
951
952
|
type: u.alphabetical,
|
|
952
953
|
"nullable-last": !1,
|
|
953
954
|
"ignore-case": !1,
|
|
954
|
-
order:
|
|
955
|
-
}), l = i.types.map((
|
|
956
|
-
group:
|
|
957
|
-
name: e.sourceCode.text.slice(...
|
|
958
|
-
size: I(
|
|
959
|
-
node:
|
|
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
|
|
960
961
|
}));
|
|
961
|
-
P(l, (
|
|
962
|
-
let
|
|
963
|
-
|
|
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({
|
|
964
965
|
messageId: "unexpectedUnionTypesOrder",
|
|
965
966
|
data: {
|
|
966
|
-
left: k(
|
|
967
|
-
right: k(
|
|
968
|
-
},
|
|
969
|
-
node:
|
|
970
|
-
fix: (
|
|
971
|
-
let
|
|
972
|
-
if (
|
|
973
|
-
let
|
|
974
|
-
|
|
975
|
-
...v(f,
|
|
976
|
-
...v(
|
|
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)
|
|
977
978
|
];
|
|
978
979
|
} else
|
|
979
|
-
|
|
980
|
-
return M(
|
|
980
|
+
t = v(l, a);
|
|
981
|
+
return M(p, l, t, e.sourceCode);
|
|
981
982
|
}
|
|
982
983
|
});
|
|
983
984
|
});
|
|
984
985
|
}
|
|
985
986
|
})
|
|
986
|
-
})
|
|
987
|
-
|
|
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,
|
|
988
998
|
meta: {
|
|
989
999
|
type: "suggestion",
|
|
990
1000
|
docs: {
|
|
@@ -998,6 +1008,15 @@ const ee = "sort-object-types", Ne = A({
|
|
|
998
1008
|
"custom-groups": {
|
|
999
1009
|
type: "object"
|
|
1000
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
|
+
},
|
|
1001
1020
|
type: {
|
|
1002
1021
|
enum: [
|
|
1003
1022
|
u.alphabetical,
|
|
@@ -1008,8 +1027,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1008
1027
|
type: "string"
|
|
1009
1028
|
},
|
|
1010
1029
|
order: {
|
|
1011
|
-
enum: [
|
|
1012
|
-
default:
|
|
1030
|
+
enum: [m.asc, m.desc],
|
|
1031
|
+
default: m.asc,
|
|
1013
1032
|
type: "string"
|
|
1014
1033
|
},
|
|
1015
1034
|
"ignore-case": {
|
|
@@ -1041,100 +1060,128 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1041
1060
|
defaultOptions: [
|
|
1042
1061
|
{
|
|
1043
1062
|
type: u.alphabetical,
|
|
1044
|
-
order:
|
|
1063
|
+
order: m.asc
|
|
1045
1064
|
}
|
|
1046
1065
|
],
|
|
1047
1066
|
create: (e) => ({
|
|
1048
1067
|
TSInterfaceDeclaration: (i) => {
|
|
1049
1068
|
if (i.body.body.length > 1) {
|
|
1050
|
-
let
|
|
1069
|
+
let a = j(e.options.at(0), {
|
|
1070
|
+
"optionality-order": G.ignore,
|
|
1051
1071
|
"partition-by-new-line": !1,
|
|
1052
1072
|
type: u.alphabetical,
|
|
1053
1073
|
"ignore-case": !1,
|
|
1054
|
-
order:
|
|
1074
|
+
order: m.asc,
|
|
1055
1075
|
"ignore-pattern": [],
|
|
1056
1076
|
"custom-groups": {},
|
|
1057
1077
|
groups: []
|
|
1058
1078
|
});
|
|
1059
|
-
if (!
|
|
1060
|
-
(l) =>
|
|
1079
|
+
if (!a["ignore-pattern"].some(
|
|
1080
|
+
(l) => U(i.id.name, l, {
|
|
1061
1081
|
nocomment: !0
|
|
1062
1082
|
})
|
|
1063
1083
|
)) {
|
|
1064
1084
|
let l = i.body.body.reduce(
|
|
1065
|
-
(
|
|
1066
|
-
var
|
|
1067
|
-
if (
|
|
1068
|
-
return
|
|
1069
|
-
let
|
|
1070
|
-
|
|
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
|
|
1071
1091
|
);
|
|
1072
|
-
if (
|
|
1073
|
-
if (
|
|
1074
|
-
({ name:
|
|
1075
|
-
else if (
|
|
1076
|
-
|
|
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}`;
|
|
1077
1097
|
else {
|
|
1078
|
-
let
|
|
1079
|
-
|
|
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);
|
|
1080
1100
|
}
|
|
1081
|
-
else if (
|
|
1082
|
-
let
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
|
1086
1106
|
);
|
|
1087
1107
|
} else {
|
|
1088
|
-
let
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
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
|
|
1092
1112
|
);
|
|
1093
1113
|
}
|
|
1094
|
-
let
|
|
1095
|
-
size: I(
|
|
1096
|
-
node:
|
|
1097
|
-
name:
|
|
1114
|
+
let b = {
|
|
1115
|
+
size: I(o.range),
|
|
1116
|
+
node: o,
|
|
1117
|
+
name: c
|
|
1098
1118
|
};
|
|
1099
|
-
return
|
|
1119
|
+
return a["partition-by-new-line"] && f && W(
|
|
1100
1120
|
e.sourceCode,
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
) &&
|
|
1104
|
-
...
|
|
1105
|
-
group:
|
|
1106
|
-
}),
|
|
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;
|
|
1107
1127
|
},
|
|
1108
1128
|
[[]]
|
|
1109
|
-
)
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
let
|
|
1113
|
-
|
|
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({
|
|
1114
1158
|
messageId: "unexpectedInterfacePropertiesOrder",
|
|
1115
1159
|
data: {
|
|
1116
|
-
left: k(
|
|
1117
|
-
right: k(
|
|
1160
|
+
left: k(o.name),
|
|
1161
|
+
right: k(f.name)
|
|
1118
1162
|
},
|
|
1119
|
-
node:
|
|
1120
|
-
fix: (
|
|
1121
|
-
let
|
|
1122
|
-
|
|
1123
|
-
let
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
)
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
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);
|
|
1134
1181
|
return M(
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1182
|
+
d,
|
|
1183
|
+
t,
|
|
1184
|
+
g,
|
|
1138
1185
|
e.sourceCode
|
|
1139
1186
|
);
|
|
1140
1187
|
}
|
|
@@ -1144,8 +1191,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1144
1191
|
}
|
|
1145
1192
|
}
|
|
1146
1193
|
})
|
|
1147
|
-
}),
|
|
1148
|
-
name:
|
|
1194
|
+
}), oe = "sort-jsx-props", Ae = A({
|
|
1195
|
+
name: oe,
|
|
1149
1196
|
meta: {
|
|
1150
1197
|
type: "suggestion",
|
|
1151
1198
|
docs: {
|
|
@@ -1169,8 +1216,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1169
1216
|
type: "string"
|
|
1170
1217
|
},
|
|
1171
1218
|
order: {
|
|
1172
|
-
enum: [
|
|
1173
|
-
default:
|
|
1219
|
+
enum: [m.asc, m.desc],
|
|
1220
|
+
default: m.asc,
|
|
1174
1221
|
type: "string"
|
|
1175
1222
|
},
|
|
1176
1223
|
groups: {
|
|
@@ -1191,64 +1238,64 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1191
1238
|
defaultOptions: [
|
|
1192
1239
|
{
|
|
1193
1240
|
type: u.alphabetical,
|
|
1194
|
-
order:
|
|
1241
|
+
order: m.asc
|
|
1195
1242
|
}
|
|
1196
1243
|
],
|
|
1197
|
-
create: (e) => [".svelte", ".astro", ".vue"].includes(
|
|
1244
|
+
create: (e) => [".svelte", ".astro", ".vue"].includes(q.extname(e.filename)) ? {} : {
|
|
1198
1245
|
JSXElement: (i) => {
|
|
1199
1246
|
if (i.openingElement.attributes.length > 1) {
|
|
1200
|
-
let
|
|
1247
|
+
let a = j(e.options.at(0), {
|
|
1201
1248
|
type: u.alphabetical,
|
|
1202
1249
|
"ignore-case": !1,
|
|
1203
|
-
order:
|
|
1250
|
+
order: m.asc,
|
|
1204
1251
|
"custom-groups": {},
|
|
1205
1252
|
groups: []
|
|
1206
1253
|
}), l = i.openingElement.attributes.reduce(
|
|
1207
|
-
(
|
|
1208
|
-
if (
|
|
1209
|
-
return
|
|
1210
|
-
let
|
|
1211
|
-
|
|
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
|
|
1212
1259
|
);
|
|
1213
|
-
|
|
1260
|
+
o(a["custom-groups"], n), r.value === null && t("shorthand"), r.loc.start.line !== r.loc.end.line && t("multiline");
|
|
1214
1261
|
let f = {
|
|
1215
|
-
size: I(
|
|
1216
|
-
group:
|
|
1217
|
-
node:
|
|
1218
|
-
name:
|
|
1262
|
+
size: I(r.range),
|
|
1263
|
+
group: p(),
|
|
1264
|
+
node: r,
|
|
1265
|
+
name: n
|
|
1219
1266
|
};
|
|
1220
|
-
return
|
|
1267
|
+
return s.at(-1).push(f), s;
|
|
1221
1268
|
},
|
|
1222
1269
|
[[]]
|
|
1223
1270
|
);
|
|
1224
|
-
for (let
|
|
1225
|
-
P(
|
|
1226
|
-
let
|
|
1227
|
-
(
|
|
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({
|
|
1228
1275
|
messageId: "unexpectedJSXPropsOrder",
|
|
1229
1276
|
data: {
|
|
1230
|
-
left:
|
|
1231
|
-
right:
|
|
1277
|
+
left: r.name,
|
|
1278
|
+
right: n.name
|
|
1232
1279
|
},
|
|
1233
|
-
node:
|
|
1234
|
-
fix: (
|
|
1280
|
+
node: n.node,
|
|
1281
|
+
fix: (o) => {
|
|
1235
1282
|
let f = {};
|
|
1236
|
-
for (let d of
|
|
1237
|
-
let
|
|
1238
|
-
|
|
1239
|
-
[...f[
|
|
1240
|
-
|
|
1241
|
-
) : 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];
|
|
1242
1289
|
}
|
|
1243
|
-
let
|
|
1290
|
+
let c = [];
|
|
1244
1291
|
for (let d of Object.keys(f).sort(
|
|
1245
|
-
(
|
|
1292
|
+
(g, y) => Number(g) - Number(y)
|
|
1246
1293
|
))
|
|
1247
|
-
|
|
1294
|
+
c.push(...v(f[d], a));
|
|
1248
1295
|
return M(
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1296
|
+
o,
|
|
1297
|
+
s,
|
|
1298
|
+
c,
|
|
1252
1299
|
e.sourceCode
|
|
1253
1300
|
);
|
|
1254
1301
|
}
|
|
@@ -1257,8 +1304,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1257
1304
|
}
|
|
1258
1305
|
}
|
|
1259
1306
|
}
|
|
1260
|
-
}),
|
|
1261
|
-
name:
|
|
1307
|
+
}), ne = "sort-exports", Ie = A({
|
|
1308
|
+
name: ne,
|
|
1262
1309
|
meta: {
|
|
1263
1310
|
type: "suggestion",
|
|
1264
1311
|
docs: {
|
|
@@ -1279,8 +1326,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1279
1326
|
type: "string"
|
|
1280
1327
|
},
|
|
1281
1328
|
order: {
|
|
1282
|
-
enum: [
|
|
1283
|
-
default:
|
|
1329
|
+
enum: [m.asc, m.desc],
|
|
1330
|
+
default: m.asc,
|
|
1284
1331
|
type: "string"
|
|
1285
1332
|
},
|
|
1286
1333
|
"ignore-case": {
|
|
@@ -1298,40 +1345,40 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1298
1345
|
defaultOptions: [
|
|
1299
1346
|
{
|
|
1300
1347
|
type: u.alphabetical,
|
|
1301
|
-
order:
|
|
1348
|
+
order: m.asc
|
|
1302
1349
|
}
|
|
1303
1350
|
],
|
|
1304
1351
|
create: (e) => {
|
|
1305
1352
|
let i = j(e.options.at(0), {
|
|
1306
1353
|
type: u.alphabetical,
|
|
1307
|
-
order:
|
|
1354
|
+
order: m.asc,
|
|
1308
1355
|
"ignore-case": !1
|
|
1309
|
-
}),
|
|
1310
|
-
|
|
1311
|
-
size: I(
|
|
1312
|
-
name:
|
|
1313
|
-
node:
|
|
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
|
|
1314
1361
|
});
|
|
1315
1362
|
};
|
|
1316
1363
|
return {
|
|
1317
1364
|
ExportAllDeclaration: l,
|
|
1318
|
-
ExportNamedDeclaration: (
|
|
1319
|
-
|
|
1365
|
+
ExportNamedDeclaration: (s) => {
|
|
1366
|
+
s.source !== null && l(s);
|
|
1320
1367
|
},
|
|
1321
1368
|
"Program:exit": () => {
|
|
1322
|
-
for (let
|
|
1323
|
-
P(
|
|
1324
|
-
O(
|
|
1369
|
+
for (let s of a)
|
|
1370
|
+
P(s, (r, n) => {
|
|
1371
|
+
O(w(r, n, i)) && e.report({
|
|
1325
1372
|
messageId: "unexpectedExportsOrder",
|
|
1326
1373
|
data: {
|
|
1327
|
-
left:
|
|
1328
|
-
right:
|
|
1374
|
+
left: r.name,
|
|
1375
|
+
right: n.name
|
|
1329
1376
|
},
|
|
1330
|
-
node:
|
|
1331
|
-
fix: (
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
v(
|
|
1377
|
+
node: n.node,
|
|
1378
|
+
fix: (p) => M(
|
|
1379
|
+
p,
|
|
1380
|
+
s,
|
|
1381
|
+
v(s, i),
|
|
1335
1382
|
e.sourceCode
|
|
1336
1383
|
)
|
|
1337
1384
|
});
|
|
@@ -1339,8 +1386,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1339
1386
|
}
|
|
1340
1387
|
};
|
|
1341
1388
|
}
|
|
1342
|
-
}),
|
|
1343
|
-
name:
|
|
1389
|
+
}), le = "sort-imports", Oe = A({
|
|
1390
|
+
name: le,
|
|
1344
1391
|
meta: {
|
|
1345
1392
|
type: "suggestion",
|
|
1346
1393
|
docs: {
|
|
@@ -1374,8 +1421,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1374
1421
|
type: "string"
|
|
1375
1422
|
},
|
|
1376
1423
|
order: {
|
|
1377
|
-
enum: [
|
|
1378
|
-
default:
|
|
1424
|
+
enum: [m.asc, m.desc],
|
|
1425
|
+
default: m.asc,
|
|
1379
1426
|
type: "string"
|
|
1380
1427
|
},
|
|
1381
1428
|
"ignore-case": {
|
|
@@ -1444,7 +1491,7 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1444
1491
|
defaultOptions: [
|
|
1445
1492
|
{
|
|
1446
1493
|
type: u.alphabetical,
|
|
1447
|
-
order:
|
|
1494
|
+
order: m.asc
|
|
1448
1495
|
}
|
|
1449
1496
|
],
|
|
1450
1497
|
create: (e) => {
|
|
@@ -1453,21 +1500,21 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1453
1500
|
"custom-groups": { type: {}, value: {} },
|
|
1454
1501
|
"internal-pattern": ["~/**"],
|
|
1455
1502
|
type: u.alphabetical,
|
|
1456
|
-
order:
|
|
1503
|
+
order: m.asc,
|
|
1457
1504
|
"ignore-case": !1,
|
|
1458
1505
|
groups: []
|
|
1459
|
-
}),
|
|
1460
|
-
for (let
|
|
1461
|
-
if (Array.isArray(
|
|
1462
|
-
for (let
|
|
1463
|
-
|
|
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);
|
|
1464
1511
|
else
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
let l = [],
|
|
1468
|
-
let
|
|
1469
|
-
(
|
|
1470
|
-
), f = (
|
|
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) => [
|
|
1471
1518
|
"./index.d.js",
|
|
1472
1519
|
"./index.d.ts",
|
|
1473
1520
|
"./index.js",
|
|
@@ -1475,12 +1522,12 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1475
1522
|
"./index",
|
|
1476
1523
|
"./",
|
|
1477
1524
|
"."
|
|
1478
|
-
].includes(
|
|
1479
|
-
(
|
|
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, {
|
|
1480
1527
|
nocomment: !0
|
|
1481
1528
|
})
|
|
1482
|
-
),
|
|
1483
|
-
let
|
|
1529
|
+
), h = (x) => {
|
|
1530
|
+
let S = [
|
|
1484
1531
|
"bun",
|
|
1485
1532
|
"bun:ffi",
|
|
1486
1533
|
"bun:jsc",
|
|
@@ -1491,98 +1538,98 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1491
1538
|
"undici",
|
|
1492
1539
|
"ws"
|
|
1493
1540
|
];
|
|
1494
|
-
return
|
|
1495
|
-
|
|
1496
|
-
) ||
|
|
1497
|
-
}, N = (
|
|
1498
|
-
return
|
|
1499
|
-
},
|
|
1500
|
-
let
|
|
1501
|
-
|
|
1502
|
-
size: I(
|
|
1503
|
-
group: t
|
|
1504
|
-
name:
|
|
1505
|
-
node:
|
|
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,
|
|
1506
1553
|
...i.type === u["line-length"] && i["max-line-length"] && {
|
|
1507
|
-
hasMultipleImportDeclarations:
|
|
1508
|
-
|
|
1554
|
+
hasMultipleImportDeclarations: n(
|
|
1555
|
+
t
|
|
1509
1556
|
)
|
|
1510
1557
|
}
|
|
1511
1558
|
});
|
|
1512
1559
|
};
|
|
1513
1560
|
return {
|
|
1514
|
-
TSImportEqualsDeclaration:
|
|
1515
|
-
ImportDeclaration:
|
|
1561
|
+
TSImportEqualsDeclaration: p,
|
|
1562
|
+
ImportDeclaration: p,
|
|
1516
1563
|
"Program:exit": () => {
|
|
1517
|
-
var
|
|
1518
|
-
let
|
|
1564
|
+
var c;
|
|
1565
|
+
let t = (d, g) => !!e.sourceCode.getTokensBetween(
|
|
1519
1566
|
d.node,
|
|
1520
|
-
|
|
1567
|
+
K(g.node, e.sourceCode) || g.node,
|
|
1521
1568
|
{
|
|
1522
1569
|
includeComments: !0
|
|
1523
1570
|
}
|
|
1524
|
-
).length,
|
|
1525
|
-
let
|
|
1526
|
-
for (let
|
|
1527
|
-
let N =
|
|
1528
|
-
N in
|
|
1529
|
-
[...
|
|
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],
|
|
1530
1577
|
i
|
|
1531
|
-
) :
|
|
1578
|
+
) : b[N] = [h];
|
|
1532
1579
|
}
|
|
1533
|
-
let C = Object.keys(
|
|
1534
|
-
(
|
|
1535
|
-
...
|
|
1536
|
-
...
|
|
1580
|
+
let C = Object.keys(b).sort((h, N) => Number(h) - Number(N)).reduce(
|
|
1581
|
+
(h, N) => [
|
|
1582
|
+
...h,
|
|
1583
|
+
...b[N]
|
|
1537
1584
|
],
|
|
1538
1585
|
[]
|
|
1539
1586
|
);
|
|
1540
|
-
for (let
|
|
1541
|
-
let
|
|
1542
|
-
if (
|
|
1587
|
+
for (let h = 0, N = C.length; h < N; h++) {
|
|
1588
|
+
let x = C.at(h);
|
|
1589
|
+
if (y.push(
|
|
1543
1590
|
d.replaceTextRange(
|
|
1544
|
-
|
|
1591
|
+
L(g.at(h).node, e.sourceCode),
|
|
1545
1592
|
e.sourceCode.text.slice(
|
|
1546
|
-
...
|
|
1593
|
+
...L(x.node, e.sourceCode)
|
|
1547
1594
|
)
|
|
1548
1595
|
)
|
|
1549
1596
|
), i["newlines-between"] !== "ignore") {
|
|
1550
|
-
let
|
|
1551
|
-
if (
|
|
1552
|
-
let
|
|
1597
|
+
let S = C.at(h + 1);
|
|
1598
|
+
if (S) {
|
|
1599
|
+
let $ = W(
|
|
1553
1600
|
e.sourceCode,
|
|
1554
|
-
|
|
1555
|
-
|
|
1601
|
+
g.at(h),
|
|
1602
|
+
g.at(h + 1)
|
|
1556
1603
|
);
|
|
1557
|
-
(i["newlines-between"] === "always" &&
|
|
1604
|
+
(i["newlines-between"] === "always" && E(i.groups, x) === E(i.groups, S) && $ !== 0 || i["newlines-between"] === "never" && $ > 0) && y.push(
|
|
1558
1605
|
d.removeRange([
|
|
1559
|
-
|
|
1560
|
-
|
|
1606
|
+
L(
|
|
1607
|
+
g.at(h).node,
|
|
1561
1608
|
e.sourceCode
|
|
1562
1609
|
).at(1),
|
|
1563
|
-
|
|
1564
|
-
|
|
1610
|
+
L(
|
|
1611
|
+
g.at(h + 1).node,
|
|
1565
1612
|
e.sourceCode
|
|
1566
1613
|
).at(0) - 1
|
|
1567
1614
|
])
|
|
1568
|
-
), i["newlines-between"] === "always" &&
|
|
1615
|
+
), i["newlines-between"] === "always" && E(i.groups, x) !== E(i.groups, S) && $ > 1 && y.push(
|
|
1569
1616
|
d.replaceTextRange(
|
|
1570
1617
|
[
|
|
1571
|
-
|
|
1572
|
-
|
|
1618
|
+
L(
|
|
1619
|
+
g.at(h).node,
|
|
1573
1620
|
e.sourceCode
|
|
1574
1621
|
).at(1),
|
|
1575
|
-
|
|
1576
|
-
|
|
1622
|
+
L(
|
|
1623
|
+
g.at(h + 1).node,
|
|
1577
1624
|
e.sourceCode
|
|
1578
1625
|
).at(0) - 1
|
|
1579
1626
|
],
|
|
1580
1627
|
`
|
|
1581
1628
|
`
|
|
1582
1629
|
)
|
|
1583
|
-
), i["newlines-between"] === "always" &&
|
|
1630
|
+
), i["newlines-between"] === "always" && E(i.groups, x) !== E(i.groups, S) && $ === 0 && y.push(
|
|
1584
1631
|
d.insertTextAfterRange(
|
|
1585
|
-
|
|
1632
|
+
L(g.at(h).node, e.sourceCode),
|
|
1586
1633
|
`
|
|
1587
1634
|
`
|
|
1588
1635
|
)
|
|
@@ -1590,58 +1637,58 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1590
1637
|
}
|
|
1591
1638
|
}
|
|
1592
1639
|
}
|
|
1593
|
-
return
|
|
1640
|
+
return y;
|
|
1594
1641
|
}, f = [[]];
|
|
1595
1642
|
for (let d of l) {
|
|
1596
|
-
let
|
|
1597
|
-
|
|
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);
|
|
1598
1645
|
}
|
|
1599
1646
|
for (let d of f)
|
|
1600
|
-
P(d, (
|
|
1601
|
-
let
|
|
1647
|
+
P(d, (g, y) => {
|
|
1648
|
+
let b = E(i.groups, g), C = E(i.groups, y), h = W(
|
|
1602
1649
|
e.sourceCode,
|
|
1603
|
-
|
|
1604
|
-
|
|
1650
|
+
g,
|
|
1651
|
+
y
|
|
1605
1652
|
);
|
|
1606
|
-
!(
|
|
1653
|
+
!(s(g.node) && s(y.node)) && !t(g, y) && (b > C || b === C && O(w(g, y, i))) && e.report({
|
|
1607
1654
|
messageId: "unexpectedImportsOrder",
|
|
1608
1655
|
data: {
|
|
1609
|
-
left:
|
|
1610
|
-
right:
|
|
1656
|
+
left: g.name,
|
|
1657
|
+
right: y.name
|
|
1611
1658
|
},
|
|
1612
|
-
node:
|
|
1613
|
-
fix: (N) =>
|
|
1614
|
-
}), i["newlines-between"] === "never" &&
|
|
1659
|
+
node: y.node,
|
|
1660
|
+
fix: (N) => o(N, d)
|
|
1661
|
+
}), i["newlines-between"] === "never" && h > 0 && e.report({
|
|
1615
1662
|
messageId: "extraSpacingBetweenImports",
|
|
1616
1663
|
data: {
|
|
1617
|
-
left:
|
|
1618
|
-
right:
|
|
1664
|
+
left: g.name,
|
|
1665
|
+
right: y.name
|
|
1619
1666
|
},
|
|
1620
|
-
node:
|
|
1621
|
-
fix: (N) =>
|
|
1622
|
-
}), i["newlines-between"] === "always" && (
|
|
1667
|
+
node: y.node,
|
|
1668
|
+
fix: (N) => o(N, d)
|
|
1669
|
+
}), i["newlines-between"] === "always" && (b < C && h === 0 ? e.report({
|
|
1623
1670
|
messageId: "missedSpacingBetweenImports",
|
|
1624
1671
|
data: {
|
|
1625
|
-
left:
|
|
1626
|
-
right:
|
|
1672
|
+
left: g.name,
|
|
1673
|
+
right: y.name
|
|
1627
1674
|
},
|
|
1628
|
-
node:
|
|
1629
|
-
fix: (N) =>
|
|
1630
|
-
}) : (
|
|
1675
|
+
node: y.node,
|
|
1676
|
+
fix: (N) => o(N, d)
|
|
1677
|
+
}) : (h > 1 || b === C && h > 0) && e.report({
|
|
1631
1678
|
messageId: "extraSpacingBetweenImports",
|
|
1632
1679
|
data: {
|
|
1633
|
-
left:
|
|
1634
|
-
right:
|
|
1680
|
+
left: g.name,
|
|
1681
|
+
right: y.name
|
|
1635
1682
|
},
|
|
1636
|
-
node:
|
|
1637
|
-
fix: (N) =>
|
|
1683
|
+
node: y.node,
|
|
1684
|
+
fix: (N) => o(N, d)
|
|
1638
1685
|
}));
|
|
1639
1686
|
});
|
|
1640
1687
|
}
|
|
1641
1688
|
};
|
|
1642
1689
|
}
|
|
1643
|
-
}),
|
|
1644
|
-
name:
|
|
1690
|
+
}), ie = "sort-objects", je = A({
|
|
1691
|
+
name: ie,
|
|
1645
1692
|
meta: {
|
|
1646
1693
|
type: "suggestion",
|
|
1647
1694
|
docs: {
|
|
@@ -1677,8 +1724,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1677
1724
|
type: "string"
|
|
1678
1725
|
},
|
|
1679
1726
|
order: {
|
|
1680
|
-
enum: [
|
|
1681
|
-
default:
|
|
1727
|
+
enum: [m.asc, m.desc],
|
|
1728
|
+
default: m.asc,
|
|
1682
1729
|
type: "string"
|
|
1683
1730
|
},
|
|
1684
1731
|
"ignore-case": {
|
|
@@ -1705,11 +1752,11 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1705
1752
|
defaultOptions: [
|
|
1706
1753
|
{
|
|
1707
1754
|
type: u.alphabetical,
|
|
1708
|
-
order:
|
|
1755
|
+
order: m.asc
|
|
1709
1756
|
}
|
|
1710
1757
|
],
|
|
1711
1758
|
create: (e) => {
|
|
1712
|
-
let i = (
|
|
1759
|
+
let i = (a) => {
|
|
1713
1760
|
let l = j(e.options.at(0), {
|
|
1714
1761
|
"partition-by-new-line": !1,
|
|
1715
1762
|
"partition-by-comment": !1,
|
|
@@ -1717,100 +1764,100 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1717
1764
|
"styled-components": !0,
|
|
1718
1765
|
"ignore-case": !1,
|
|
1719
1766
|
"ignore-pattern": [],
|
|
1720
|
-
order:
|
|
1767
|
+
order: m.asc,
|
|
1721
1768
|
"custom-groups": {},
|
|
1722
1769
|
groups: []
|
|
1723
|
-
}),
|
|
1724
|
-
if (!(l["ignore-pattern"].length && typeof
|
|
1725
|
-
(
|
|
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, {
|
|
1726
1773
|
nocomment: !0
|
|
1727
1774
|
})
|
|
1728
|
-
) : !1) &&
|
|
1729
|
-
let
|
|
1730
|
-
if (!l["styled-components"] && (
|
|
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)))
|
|
1731
1778
|
return;
|
|
1732
|
-
let
|
|
1733
|
-
(f,
|
|
1734
|
-
var
|
|
1735
|
-
if (
|
|
1779
|
+
let t = (o) => o.reduce(
|
|
1780
|
+
(f, c) => {
|
|
1781
|
+
var $;
|
|
1782
|
+
if (c.type === "SpreadElement" || c.type === "RestElement")
|
|
1736
1783
|
return f.push([]), f;
|
|
1737
|
-
let d =
|
|
1738
|
-
l["partition-by-comment"] && d &&
|
|
1784
|
+
let d = K(c, e.sourceCode), g = ($ = f.at(-1)) == null ? void 0 : $.at(-1);
|
|
1785
|
+
l["partition-by-comment"] && d && Y(
|
|
1739
1786
|
l["partition-by-comment"],
|
|
1740
1787
|
d.value
|
|
1741
1788
|
) && f.push([]);
|
|
1742
|
-
let
|
|
1743
|
-
|
|
1744
|
-
let
|
|
1745
|
-
size: I(
|
|
1746
|
-
node:
|
|
1747
|
-
name:
|
|
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
|
|
1748
1795
|
};
|
|
1749
|
-
l["partition-by-new-line"] &&
|
|
1750
|
-
|
|
1751
|
-
let
|
|
1752
|
-
let
|
|
1753
|
-
switch (
|
|
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) {
|
|
1754
1801
|
case "ArrowFunctionExpression":
|
|
1755
|
-
|
|
1802
|
+
z.push(D.body);
|
|
1756
1803
|
break;
|
|
1757
1804
|
case "ConditionalExpression":
|
|
1758
|
-
|
|
1805
|
+
z.push(D.consequent, D.alternate);
|
|
1759
1806
|
break;
|
|
1760
1807
|
case "LogicalExpression":
|
|
1761
1808
|
case "BinaryExpression":
|
|
1762
|
-
|
|
1809
|
+
z.push(D.left, D.right);
|
|
1763
1810
|
break;
|
|
1764
1811
|
case "CallExpression":
|
|
1765
|
-
|
|
1812
|
+
z.push(...D.arguments);
|
|
1766
1813
|
break;
|
|
1767
1814
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1815
|
+
z.forEach((_) => {
|
|
1816
|
+
_.type === "Identifier" && C.push(_.name), (_.type === "BinaryExpression" || _.type === "ConditionalExpression") && ce(_);
|
|
1770
1817
|
});
|
|
1771
1818
|
};
|
|
1772
|
-
switch (
|
|
1819
|
+
switch (V.right.type) {
|
|
1773
1820
|
case "ArrowFunctionExpression":
|
|
1774
1821
|
case "ConditionalExpression":
|
|
1775
1822
|
case "LogicalExpression":
|
|
1776
1823
|
case "BinaryExpression":
|
|
1777
1824
|
case "CallExpression":
|
|
1778
|
-
|
|
1825
|
+
ce(V.right);
|
|
1779
1826
|
break;
|
|
1780
1827
|
}
|
|
1781
|
-
})(
|
|
1782
|
-
let
|
|
1783
|
-
...
|
|
1784
|
-
group:
|
|
1828
|
+
})(c.value), N(l["custom-groups"], y);
|
|
1829
|
+
let S = {
|
|
1830
|
+
...x,
|
|
1831
|
+
group: h(),
|
|
1785
1832
|
dependencies: C,
|
|
1786
|
-
position:
|
|
1833
|
+
position: b
|
|
1787
1834
|
};
|
|
1788
|
-
return f.at(-1).push(
|
|
1835
|
+
return f.at(-1).push(S), f;
|
|
1789
1836
|
},
|
|
1790
1837
|
[[]]
|
|
1791
1838
|
);
|
|
1792
|
-
for (let
|
|
1793
|
-
P(
|
|
1794
|
-
let d =
|
|
1795
|
-
if (d >
|
|
1796
|
-
let
|
|
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) => {
|
|
1797
1844
|
let C = {};
|
|
1798
|
-
for (let N of
|
|
1799
|
-
let
|
|
1800
|
-
|
|
1801
|
-
[...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],
|
|
1802
1849
|
l
|
|
1803
|
-
) : C[
|
|
1850
|
+
) : C[x] = [N];
|
|
1804
1851
|
}
|
|
1805
|
-
let
|
|
1852
|
+
let h = [];
|
|
1806
1853
|
for (let N of Object.keys(C).sort(
|
|
1807
|
-
(
|
|
1854
|
+
(x, S) => Number(x) - Number(S)
|
|
1808
1855
|
))
|
|
1809
|
-
|
|
1856
|
+
h.push(...v(C[N], l));
|
|
1810
1857
|
return M(
|
|
1811
|
-
x,
|
|
1812
|
-
p,
|
|
1813
1858
|
b,
|
|
1859
|
+
o,
|
|
1860
|
+
h,
|
|
1814
1861
|
e.sourceCode,
|
|
1815
1862
|
{
|
|
1816
1863
|
partitionComment: l["partition-by-comment"]
|
|
@@ -1821,10 +1868,10 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1821
1868
|
messageId: "unexpectedObjectsOrder",
|
|
1822
1869
|
data: {
|
|
1823
1870
|
left: k(f.name),
|
|
1824
|
-
right: k(
|
|
1871
|
+
right: k(c.name)
|
|
1825
1872
|
},
|
|
1826
|
-
node:
|
|
1827
|
-
fix:
|
|
1873
|
+
node: c.node,
|
|
1874
|
+
fix: y
|
|
1828
1875
|
});
|
|
1829
1876
|
}
|
|
1830
1877
|
});
|
|
@@ -1835,8 +1882,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1835
1882
|
ObjectPattern: i
|
|
1836
1883
|
};
|
|
1837
1884
|
}
|
|
1838
|
-
}),
|
|
1839
|
-
name:
|
|
1885
|
+
}), pe = "sort-classes", Pe = A({
|
|
1886
|
+
name: pe,
|
|
1840
1887
|
meta: {
|
|
1841
1888
|
type: "suggestion",
|
|
1842
1889
|
docs: {
|
|
@@ -1861,8 +1908,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1861
1908
|
default: !1
|
|
1862
1909
|
},
|
|
1863
1910
|
order: {
|
|
1864
|
-
enum: [
|
|
1865
|
-
default:
|
|
1911
|
+
enum: [m.asc, m.desc],
|
|
1912
|
+
default: m.asc,
|
|
1866
1913
|
type: "string"
|
|
1867
1914
|
},
|
|
1868
1915
|
groups: {
|
|
@@ -1880,85 +1927,85 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1880
1927
|
defaultOptions: [
|
|
1881
1928
|
{
|
|
1882
1929
|
type: u.alphabetical,
|
|
1883
|
-
order:
|
|
1930
|
+
order: m.asc
|
|
1884
1931
|
}
|
|
1885
1932
|
],
|
|
1886
1933
|
create: (e) => ({
|
|
1887
1934
|
ClassBody: (i) => {
|
|
1888
1935
|
if (i.body.length > 1) {
|
|
1889
|
-
let
|
|
1936
|
+
let a = j(e.options.at(0), {
|
|
1890
1937
|
type: u.alphabetical,
|
|
1891
|
-
order:
|
|
1938
|
+
order: m.asc,
|
|
1892
1939
|
"ignore-case": !1,
|
|
1893
1940
|
groups: ["property", "constructor", "method", "unknown"]
|
|
1894
|
-
}), l = i.body.map((
|
|
1941
|
+
}), l = i.body.map((s) => {
|
|
1895
1942
|
var f;
|
|
1896
|
-
let
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
((f =
|
|
1900
|
-
) :
|
|
1901
|
-
let
|
|
1902
|
-
if (
|
|
1903
|
-
|
|
1904
|
-
let
|
|
1905
|
-
|
|
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");
|
|
1906
1953
|
} else
|
|
1907
|
-
|
|
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"));
|
|
1908
1955
|
return {
|
|
1909
|
-
size: I(
|
|
1910
|
-
group:
|
|
1911
|
-
node:
|
|
1912
|
-
name:
|
|
1956
|
+
size: I(s.range),
|
|
1957
|
+
group: n(),
|
|
1958
|
+
node: s,
|
|
1959
|
+
name: r
|
|
1913
1960
|
};
|
|
1914
1961
|
});
|
|
1915
|
-
P(l, (
|
|
1916
|
-
let
|
|
1917
|
-
|
|
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({
|
|
1918
1965
|
messageId: "unexpectedClassesOrder",
|
|
1919
1966
|
data: {
|
|
1920
|
-
left: k(
|
|
1921
|
-
right: k(
|
|
1967
|
+
left: k(s.name),
|
|
1968
|
+
right: k(r.name)
|
|
1922
1969
|
},
|
|
1923
|
-
node:
|
|
1924
|
-
fix: (
|
|
1925
|
-
let
|
|
1926
|
-
(d,
|
|
1927
|
-
let
|
|
1928
|
-
return
|
|
1929
|
-
[...d[
|
|
1930
|
-
|
|
1931
|
-
) : d[
|
|
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;
|
|
1932
1979
|
},
|
|
1933
1980
|
{}
|
|
1934
|
-
),
|
|
1935
|
-
(d,
|
|
1981
|
+
), c = Object.keys(f).sort((d, g) => Number(d) - Number(g)).reduce(
|
|
1982
|
+
(d, g) => [
|
|
1936
1983
|
...d,
|
|
1937
|
-
...f[
|
|
1984
|
+
...f[g]
|
|
1938
1985
|
],
|
|
1939
1986
|
[]
|
|
1940
1987
|
);
|
|
1941
|
-
for (let d = 0,
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
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),
|
|
1945
1992
|
e.sourceCode.text.slice(
|
|
1946
|
-
...
|
|
1947
|
-
|
|
1993
|
+
...L(
|
|
1994
|
+
c.at(d).node,
|
|
1948
1995
|
e.sourceCode
|
|
1949
1996
|
)
|
|
1950
1997
|
)
|
|
1951
1998
|
)
|
|
1952
1999
|
);
|
|
1953
|
-
return
|
|
2000
|
+
return o;
|
|
1954
2001
|
}
|
|
1955
2002
|
});
|
|
1956
2003
|
});
|
|
1957
2004
|
}
|
|
1958
2005
|
}
|
|
1959
2006
|
})
|
|
1960
|
-
}),
|
|
1961
|
-
name:
|
|
2007
|
+
}), ue = "sort-enums", Te = A({
|
|
2008
|
+
name: ue,
|
|
1962
2009
|
meta: {
|
|
1963
2010
|
type: "suggestion",
|
|
1964
2011
|
docs: {
|
|
@@ -1987,8 +2034,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
1987
2034
|
default: !1
|
|
1988
2035
|
},
|
|
1989
2036
|
order: {
|
|
1990
|
-
enum: [
|
|
1991
|
-
default:
|
|
2037
|
+
enum: [m.asc, m.desc],
|
|
2038
|
+
default: m.asc,
|
|
1992
2039
|
type: "string"
|
|
1993
2040
|
}
|
|
1994
2041
|
},
|
|
@@ -2002,43 +2049,43 @@ const ee = "sort-object-types", Ne = A({
|
|
|
2002
2049
|
defaultOptions: [
|
|
2003
2050
|
{
|
|
2004
2051
|
type: u.alphabetical,
|
|
2005
|
-
order:
|
|
2052
|
+
order: m.asc
|
|
2006
2053
|
}
|
|
2007
2054
|
],
|
|
2008
2055
|
create: (e) => ({
|
|
2009
2056
|
TSEnumDeclaration: (i) => {
|
|
2010
|
-
if (i.members.length > 1 && i.members.every(({ initializer:
|
|
2011
|
-
let
|
|
2057
|
+
if (i.members.length > 1 && i.members.every(({ initializer: a }) => a)) {
|
|
2058
|
+
let a = j(e.options.at(0), {
|
|
2012
2059
|
type: u.alphabetical,
|
|
2013
|
-
order:
|
|
2060
|
+
order: m.asc,
|
|
2014
2061
|
"ignore-case": !1,
|
|
2015
2062
|
"partition-by-comment": !1
|
|
2016
|
-
}), l =
|
|
2017
|
-
(
|
|
2018
|
-
let
|
|
2019
|
-
l &&
|
|
2020
|
-
let
|
|
2021
|
-
name:
|
|
2022
|
-
node:
|
|
2023
|
-
size: I(
|
|
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)
|
|
2024
2071
|
};
|
|
2025
|
-
return
|
|
2072
|
+
return r.at(-1).push(o), r;
|
|
2026
2073
|
},
|
|
2027
2074
|
[[]]
|
|
2028
2075
|
);
|
|
2029
|
-
for (let
|
|
2030
|
-
P(
|
|
2031
|
-
O(
|
|
2076
|
+
for (let r of s)
|
|
2077
|
+
P(r, (n, p) => {
|
|
2078
|
+
O(w(n, p, a)) && e.report({
|
|
2032
2079
|
messageId: "unexpectedEnumsOrder",
|
|
2033
2080
|
data: {
|
|
2034
|
-
left: k(
|
|
2035
|
-
right: k(
|
|
2081
|
+
left: k(n.name),
|
|
2082
|
+
right: k(p.name)
|
|
2036
2083
|
},
|
|
2037
|
-
node:
|
|
2038
|
-
fix: (
|
|
2039
|
-
o,
|
|
2084
|
+
node: p.node,
|
|
2085
|
+
fix: (t) => M(
|
|
2040
2086
|
t,
|
|
2041
|
-
|
|
2087
|
+
r,
|
|
2088
|
+
v(r, a),
|
|
2042
2089
|
e.sourceCode,
|
|
2043
2090
|
{ partitionComment: l }
|
|
2044
2091
|
)
|
|
@@ -2047,8 +2094,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
2047
2094
|
}
|
|
2048
2095
|
}
|
|
2049
2096
|
})
|
|
2050
|
-
}),
|
|
2051
|
-
name:
|
|
2097
|
+
}), de = "sort-maps", Me = A({
|
|
2098
|
+
name: de,
|
|
2052
2099
|
meta: {
|
|
2053
2100
|
type: "suggestion",
|
|
2054
2101
|
docs: {
|
|
@@ -2069,8 +2116,8 @@ const ee = "sort-object-types", Ne = A({
|
|
|
2069
2116
|
type: "string"
|
|
2070
2117
|
},
|
|
2071
2118
|
order: {
|
|
2072
|
-
enum: [
|
|
2073
|
-
default:
|
|
2119
|
+
enum: [m.asc, m.desc],
|
|
2120
|
+
default: m.asc,
|
|
2074
2121
|
type: "string"
|
|
2075
2122
|
},
|
|
2076
2123
|
"ignore-case": {
|
|
@@ -2088,48 +2135,48 @@ const ee = "sort-object-types", Ne = A({
|
|
|
2088
2135
|
defaultOptions: [
|
|
2089
2136
|
{
|
|
2090
2137
|
type: u.alphabetical,
|
|
2091
|
-
order:
|
|
2138
|
+
order: m.asc
|
|
2092
2139
|
}
|
|
2093
2140
|
],
|
|
2094
2141
|
create: (e) => ({
|
|
2095
2142
|
NewExpression: (i) => {
|
|
2096
2143
|
if (i.callee.type === "Identifier" && i.callee.name === "Map" && i.arguments.length && i.arguments[0].type === "ArrayExpression") {
|
|
2097
|
-
let [{ elements:
|
|
2098
|
-
if (
|
|
2144
|
+
let [{ elements: a }] = i.arguments;
|
|
2145
|
+
if (a.length > 1) {
|
|
2099
2146
|
let l = j(e.options.at(0), {
|
|
2100
2147
|
type: u.alphabetical,
|
|
2101
2148
|
"ignore-case": !1,
|
|
2102
|
-
order:
|
|
2103
|
-
}),
|
|
2104
|
-
(
|
|
2149
|
+
order: m.asc
|
|
2150
|
+
}), s = a.reduce(
|
|
2151
|
+
(r, n) => (n === null || n.type === "SpreadElement" ? r.push([]) : r.at(-1).push(n), r),
|
|
2105
2152
|
[[]]
|
|
2106
2153
|
);
|
|
2107
|
-
for (let
|
|
2108
|
-
let
|
|
2109
|
-
let
|
|
2110
|
-
if (
|
|
2111
|
-
let [
|
|
2112
|
-
|
|
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}`;
|
|
2113
2160
|
} else
|
|
2114
|
-
|
|
2161
|
+
t = e.sourceCode.text.slice(...p.range);
|
|
2115
2162
|
return {
|
|
2116
|
-
size: I(
|
|
2117
|
-
node:
|
|
2118
|
-
name:
|
|
2163
|
+
size: I(p.range),
|
|
2164
|
+
node: p,
|
|
2165
|
+
name: t
|
|
2119
2166
|
};
|
|
2120
2167
|
});
|
|
2121
|
-
P(
|
|
2122
|
-
O(
|
|
2168
|
+
P(n, (p, t) => {
|
|
2169
|
+
O(w(p, t, l)) && e.report({
|
|
2123
2170
|
messageId: "unexpectedMapElementsOrder",
|
|
2124
2171
|
data: {
|
|
2125
|
-
left: k(
|
|
2126
|
-
right: k(
|
|
2172
|
+
left: k(p.name),
|
|
2173
|
+
right: k(t.name)
|
|
2127
2174
|
},
|
|
2128
|
-
node:
|
|
2129
|
-
fix: (
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
v(
|
|
2175
|
+
node: t.node,
|
|
2176
|
+
fix: (o) => M(
|
|
2177
|
+
o,
|
|
2178
|
+
n,
|
|
2179
|
+
v(n, l),
|
|
2133
2180
|
e.sourceCode
|
|
2134
2181
|
)
|
|
2135
2182
|
});
|
|
@@ -2139,10 +2186,10 @@ const ee = "sort-object-types", Ne = A({
|
|
|
2139
2186
|
}
|
|
2140
2187
|
}
|
|
2141
2188
|
})
|
|
2142
|
-
}),
|
|
2143
|
-
let
|
|
2189
|
+
}), Le = "eslint-plugin-perfectionist";
|
|
2190
|
+
let X = (e) => {
|
|
2144
2191
|
let i = {
|
|
2145
|
-
[
|
|
2192
|
+
[le]: [
|
|
2146
2193
|
"error",
|
|
2147
2194
|
{
|
|
2148
2195
|
groups: [
|
|
@@ -2163,7 +2210,7 @@ let J = (e) => {
|
|
|
2163
2210
|
"internal-pattern": ["~/**"]
|
|
2164
2211
|
}
|
|
2165
2212
|
],
|
|
2166
|
-
[
|
|
2213
|
+
[pe]: [
|
|
2167
2214
|
"error",
|
|
2168
2215
|
{
|
|
2169
2216
|
groups: [
|
|
@@ -2180,78 +2227,78 @@ let J = (e) => {
|
|
|
2180
2227
|
]
|
|
2181
2228
|
}
|
|
2182
2229
|
],
|
|
2183
|
-
[
|
|
2230
|
+
[ie]: [
|
|
2184
2231
|
"error",
|
|
2185
2232
|
{
|
|
2186
2233
|
"partition-by-comment": !1
|
|
2187
2234
|
}
|
|
2188
2235
|
],
|
|
2189
|
-
[
|
|
2236
|
+
[Z]: [
|
|
2190
2237
|
"error",
|
|
2191
2238
|
{
|
|
2192
2239
|
"spread-last": !0
|
|
2193
2240
|
}
|
|
2194
2241
|
],
|
|
2195
|
-
[q]: ["error"],
|
|
2196
2242
|
[H]: ["error"],
|
|
2197
|
-
[
|
|
2198
|
-
[Z]: ["error"],
|
|
2243
|
+
[Q]: ["error"],
|
|
2199
2244
|
[F]: ["error"],
|
|
2200
2245
|
[ee]: ["error"],
|
|
2201
2246
|
[te]: ["error"],
|
|
2202
2247
|
[re]: ["error"],
|
|
2203
2248
|
[se]: ["error"],
|
|
2204
2249
|
[ae]: ["error"],
|
|
2205
|
-
[
|
|
2206
|
-
[
|
|
2250
|
+
[oe]: ["error"],
|
|
2251
|
+
[ne]: ["error"],
|
|
2252
|
+
[ue]: ["error"],
|
|
2253
|
+
[de]: ["error"]
|
|
2207
2254
|
};
|
|
2208
2255
|
return {
|
|
2209
2256
|
rules: Object.fromEntries(
|
|
2210
|
-
Object.entries(i).map(([
|
|
2211
|
-
`perfectionist/${
|
|
2212
|
-
[l, Object.assign(
|
|
2257
|
+
Object.entries(i).map(([a, [l, s = {}]]) => [
|
|
2258
|
+
`perfectionist/${a}`,
|
|
2259
|
+
[l, Object.assign(s, e)]
|
|
2213
2260
|
])
|
|
2214
2261
|
),
|
|
2215
2262
|
plugins: ["perfectionist"]
|
|
2216
2263
|
};
|
|
2217
2264
|
};
|
|
2218
|
-
const
|
|
2265
|
+
const _e = {
|
|
2219
2266
|
rules: {
|
|
2220
|
-
[
|
|
2221
|
-
[
|
|
2222
|
-
[
|
|
2223
|
-
[
|
|
2224
|
-
[
|
|
2225
|
-
[
|
|
2226
|
-
[
|
|
2267
|
+
[Z]: Ee,
|
|
2268
|
+
[Q]: xe,
|
|
2269
|
+
[pe]: Pe,
|
|
2270
|
+
[ue]: Te,
|
|
2271
|
+
[ne]: Ie,
|
|
2272
|
+
[le]: Oe,
|
|
2273
|
+
[ae]: ke,
|
|
2274
|
+
[oe]: Ae,
|
|
2275
|
+
[de]: Me,
|
|
2276
|
+
[ee]: Ce,
|
|
2277
|
+
[te]: ve,
|
|
2278
|
+
[re]: Se,
|
|
2279
|
+
[ie]: je,
|
|
2280
|
+
[H]: be,
|
|
2227
2281
|
[se]: we,
|
|
2228
|
-
[
|
|
2229
|
-
[Z]: xe,
|
|
2230
|
-
[F]: Ee,
|
|
2231
|
-
[ee]: Ne,
|
|
2232
|
-
[ne]: Ae,
|
|
2233
|
-
[q]: ye,
|
|
2234
|
-
[te]: Ce,
|
|
2235
|
-
[Y]: be
|
|
2282
|
+
[F]: Ne
|
|
2236
2283
|
},
|
|
2237
2284
|
configs: {
|
|
2238
|
-
"recommended-alphabetical":
|
|
2285
|
+
"recommended-alphabetical": X({
|
|
2239
2286
|
type: u.alphabetical,
|
|
2240
|
-
order:
|
|
2287
|
+
order: m.asc,
|
|
2241
2288
|
"ignore-case": !1
|
|
2242
2289
|
}),
|
|
2243
|
-
"recommended-natural":
|
|
2290
|
+
"recommended-natural": X({
|
|
2244
2291
|
type: u.natural,
|
|
2245
|
-
order:
|
|
2292
|
+
order: m.asc,
|
|
2246
2293
|
"ignore-case": !1
|
|
2247
2294
|
}),
|
|
2248
|
-
"recommended-line-length":
|
|
2295
|
+
"recommended-line-length": X({
|
|
2249
2296
|
type: u["line-length"],
|
|
2250
|
-
order:
|
|
2297
|
+
order: m.desc
|
|
2251
2298
|
})
|
|
2252
2299
|
},
|
|
2253
|
-
name:
|
|
2300
|
+
name: Le
|
|
2254
2301
|
};
|
|
2255
2302
|
export {
|
|
2256
|
-
|
|
2303
|
+
_e as default
|
|
2257
2304
|
};
|