eslint-plugin-perfectionist 1.1.2 → 1.2.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/index.js +3 -3
- package/dist/index.mjs +568 -488
- package/package.json +1 -1
- package/readme.md +8 -7
package/dist/index.mjs
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var ae = Object.defineProperty;
|
|
2
|
+
var re = (t, l, s) => l in t ? ae(t, l, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[l] = s;
|
|
3
|
+
var Q = (t, l, s) => (re(t, typeof l != "symbol" ? l + "" : l, s), s);
|
|
4
4
|
import { AST_TOKEN_TYPES as C, AST_NODE_TYPES as u } from "@typescript-eslint/types";
|
|
5
|
-
import { ESLintUtils as
|
|
5
|
+
import { ESLintUtils as se, ASTUtils as $ } from "@typescript-eslint/utils";
|
|
6
6
|
import ne from "natural-compare-lite";
|
|
7
|
-
import { minimatch as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
7
|
+
import { minimatch as B } from "minimatch";
|
|
8
|
+
import Z from "is-core-module";
|
|
9
|
+
import oe from "json5";
|
|
10
|
+
import le from "path";
|
|
11
11
|
import ie from "fs";
|
|
12
|
-
let
|
|
13
|
-
(
|
|
14
|
-
), I = (
|
|
15
|
-
let [
|
|
16
|
-
return
|
|
12
|
+
let A = se.RuleCreator(
|
|
13
|
+
(t) => `https://eslint-plugin-perfectionist.azat.io/rules/${t}`
|
|
14
|
+
), I = (t) => t.replaceAll(/\s\s+/g, " ").trim(), N = (t) => {
|
|
15
|
+
let [l, s] = t;
|
|
16
|
+
return s - l;
|
|
17
17
|
};
|
|
18
|
-
var
|
|
19
|
-
let j = (
|
|
18
|
+
var i = /* @__PURE__ */ ((t) => (t.alphabetical = "alphabetical", t["line-length"] = "line-length", t.natural = "natural", t))(i || {}), d = /* @__PURE__ */ ((t) => (t.desc = "desc", t.asc = "asc", t))(d || {});
|
|
19
|
+
let j = (t, l, s) => {
|
|
20
20
|
var e, o;
|
|
21
|
-
if ((e =
|
|
21
|
+
if ((e = l.dependencies) != null && e.includes(t.name))
|
|
22
22
|
return !1;
|
|
23
|
-
if ((o =
|
|
23
|
+
if ((o = t.dependencies) != null && o.includes(l.name))
|
|
24
24
|
return !0;
|
|
25
|
-
let
|
|
26
|
-
return
|
|
27
|
-
}, S = (
|
|
28
|
-
let
|
|
29
|
-
filter: ({ type:
|
|
25
|
+
let n = s.order === "asc" ? 1 : -1, p, r = (a) => s["ignore-case"] ? a.toLowerCase() : a;
|
|
26
|
+
return s.type === i.alphabetical ? p = (a, c) => r(a.name).localeCompare(r(c.name)) : s.type === i.natural ? p = (a, c) => ne(r(a.name), r(c.name)) : p = (a, c) => a.size - c.size, n * p(t, l) > 0;
|
|
27
|
+
}, S = (t, l) => [...t].sort((s, n) => Number(j(s, n, l)) || -1), pe = (t, l) => {
|
|
28
|
+
let s = l.getTokenAfter(t, {
|
|
29
|
+
filter: ({ type: n, value: p }) => !(n === C.Punctuator && [",", ";"].includes(p)),
|
|
30
30
|
includeComments: !0
|
|
31
31
|
});
|
|
32
|
-
return ((
|
|
33
|
-
},
|
|
34
|
-
let [
|
|
35
|
-
filter: ({ type:
|
|
32
|
+
return ((s == null ? void 0 : s.type) === C.Block || (s == null ? void 0 : s.type) === C.Line) && t.loc.end.line === s.loc.end.line ? s : null;
|
|
33
|
+
}, F = (t, l) => {
|
|
34
|
+
let [s, n] = l.getTokensBefore(t, {
|
|
35
|
+
filter: ({ type: p, value: r }) => !(p === C.Punctuator && [",", ";"].includes(r)),
|
|
36
36
|
includeComments: !0,
|
|
37
37
|
count: 2
|
|
38
38
|
});
|
|
39
|
-
return ((
|
|
40
|
-
}, T = (
|
|
39
|
+
return ((n == null ? void 0 : n.type) === C.Block || (n == null ? void 0 : n.type) === C.Line) && t.loc.start.line - n.loc.end.line <= 1 && (s == null ? void 0 : s.loc.end.line) !== n.loc.start.line ? n : null;
|
|
40
|
+
}, T = (t, l) => {
|
|
41
41
|
var e;
|
|
42
|
-
let
|
|
43
|
-
if ($.isParenthesized(
|
|
44
|
-
let o =
|
|
45
|
-
|
|
42
|
+
let s = t.range.at(0), n = t.range.at(1), p = l.text.slice(s, n);
|
|
43
|
+
if ($.isParenthesized(t, l)) {
|
|
44
|
+
let o = l.getTokenBefore(
|
|
45
|
+
t,
|
|
46
46
|
$.isOpeningParenToken
|
|
47
|
-
),
|
|
48
|
-
|
|
47
|
+
), a = l.getTokenAfter(
|
|
48
|
+
t,
|
|
49
49
|
$.isClosingParenToken
|
|
50
50
|
);
|
|
51
|
-
|
|
51
|
+
s = o.range.at(0), n = a.range.at(1);
|
|
52
52
|
}
|
|
53
|
-
let r =
|
|
54
|
-
if (
|
|
55
|
-
let o =
|
|
53
|
+
let r = F(t, l);
|
|
54
|
+
if (p.endsWith(";") || p.endsWith(",")) {
|
|
55
|
+
let o = l.getTokensAfter(t, {
|
|
56
56
|
includeComments: !0,
|
|
57
57
|
count: 2
|
|
58
58
|
});
|
|
59
|
-
|
|
59
|
+
t.loc.start.line === ((e = o.at(1)) == null ? void 0 : e.loc.start.line) && (n -= 1);
|
|
60
60
|
}
|
|
61
|
-
return r && (
|
|
62
|
-
}, v = (
|
|
63
|
-
let
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
T(r,
|
|
68
|
-
|
|
61
|
+
return r && (s = r.range.at(0)), [s, n];
|
|
62
|
+
}, v = (t, l, s, n) => {
|
|
63
|
+
let p = [];
|
|
64
|
+
return l.forEach(({ node: r }, e) => {
|
|
65
|
+
p.push(
|
|
66
|
+
t.replaceTextRange(
|
|
67
|
+
T(r, n),
|
|
68
|
+
n.text.slice(...T(s[e].node, n))
|
|
69
69
|
)
|
|
70
70
|
);
|
|
71
|
-
let o =
|
|
71
|
+
let o = pe(s[e].node, n);
|
|
72
72
|
if (o) {
|
|
73
|
-
let
|
|
74
|
-
|
|
73
|
+
let c = [
|
|
74
|
+
n.getTokenBefore(o).range.at(1),
|
|
75
75
|
o.range.at(1)
|
|
76
76
|
];
|
|
77
|
-
|
|
78
|
-
let g =
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
p.push(t.replaceTextRange(c, ""));
|
|
78
|
+
let g = n.getTokenAfter(r);
|
|
79
|
+
p.push(
|
|
80
|
+
t.insertTextAfter(
|
|
81
81
|
(g == null ? void 0 : g.loc.end.line) === r.loc.end.line ? g : r,
|
|
82
|
-
|
|
82
|
+
n.text.slice(...c)
|
|
83
83
|
)
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
|
-
}),
|
|
87
|
-
},
|
|
88
|
-
if (
|
|
89
|
-
for (let
|
|
90
|
-
let
|
|
91
|
-
|
|
86
|
+
}), p;
|
|
87
|
+
}, k = (t = {}, l) => Object.assign(l, t), P = (t, l) => {
|
|
88
|
+
if (t.length > 1)
|
|
89
|
+
for (let s = 1; s < t.length; s++) {
|
|
90
|
+
let n = t.at(s - 1), p = t.at(s);
|
|
91
|
+
n && p && l(n, p, s - 1);
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
|
-
const _ = "sort-array-includes",
|
|
94
|
+
const _ = "sort-array-includes", ce = A({
|
|
95
95
|
name: _,
|
|
96
96
|
meta: {
|
|
97
97
|
type: "suggestion",
|
|
@@ -106,15 +106,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
106
106
|
properties: {
|
|
107
107
|
type: {
|
|
108
108
|
enum: [
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
i.alphabetical,
|
|
110
|
+
i.natural,
|
|
111
|
+
i["line-length"]
|
|
112
112
|
],
|
|
113
|
-
default:
|
|
113
|
+
default: i.natural
|
|
114
114
|
},
|
|
115
115
|
order: {
|
|
116
|
-
enum: [
|
|
117
|
-
default:
|
|
116
|
+
enum: [d.asc, d.desc],
|
|
117
|
+
default: d.asc
|
|
118
118
|
},
|
|
119
119
|
"ignore-case": {
|
|
120
120
|
type: "boolean",
|
|
@@ -134,43 +134,43 @@ const _ = "sort-array-includes", pe = k({
|
|
|
134
134
|
},
|
|
135
135
|
defaultOptions: [
|
|
136
136
|
{
|
|
137
|
-
type:
|
|
138
|
-
order:
|
|
137
|
+
type: i.alphabetical,
|
|
138
|
+
order: d.asc
|
|
139
139
|
}
|
|
140
140
|
],
|
|
141
|
-
create: (
|
|
142
|
-
MemberExpression: (
|
|
143
|
-
if ((
|
|
144
|
-
let
|
|
145
|
-
if (
|
|
146
|
-
let
|
|
147
|
-
type:
|
|
148
|
-
order:
|
|
141
|
+
create: (t) => ({
|
|
142
|
+
MemberExpression: (l) => {
|
|
143
|
+
if ((l.object.type === u.ArrayExpression || l.object.type === u.NewExpression) && l.property.type === u.Identifier && l.property.name === "includes") {
|
|
144
|
+
let s = l.object.type === u.ArrayExpression ? l.object.elements : l.object.arguments;
|
|
145
|
+
if (s.length > 1) {
|
|
146
|
+
let n = k(t.options.at(0), {
|
|
147
|
+
type: i.alphabetical,
|
|
148
|
+
order: d.asc,
|
|
149
149
|
"ignore-case": !1,
|
|
150
150
|
"spread-last": !1
|
|
151
|
-
}),
|
|
151
|
+
}), p = t.getSourceCode(), r = s.reduce(
|
|
152
152
|
(e, o) => (o !== null && e.at(0).push({
|
|
153
|
-
name: o.type === u.Literal ? o.raw :
|
|
154
|
-
size:
|
|
153
|
+
name: o.type === u.Literal ? o.raw : p.text.slice(...o.range),
|
|
154
|
+
size: N(o.range),
|
|
155
155
|
type: o.type,
|
|
156
156
|
node: o
|
|
157
157
|
}), e),
|
|
158
158
|
[[], []]
|
|
159
159
|
).flat();
|
|
160
160
|
P(r, (e, o) => {
|
|
161
|
-
let
|
|
162
|
-
|
|
161
|
+
let a;
|
|
162
|
+
n["spread-last"] && e.node.type === u.Literal && o.node.type === u.SpreadElement ? a = !1 : n["spread-last"] && e.node.type === u.SpreadElement && o.node.type === u.Literal ? a = !0 : a = j(e, o, n), a && t.report({
|
|
163
163
|
messageId: "unexpectedArrayIncludesOrder",
|
|
164
164
|
data: {
|
|
165
165
|
left: I(e.name),
|
|
166
166
|
right: I(o.name)
|
|
167
167
|
},
|
|
168
168
|
node: o.node,
|
|
169
|
-
fix: (
|
|
170
|
-
let g = S(r,
|
|
171
|
-
return
|
|
169
|
+
fix: (c) => {
|
|
170
|
+
let g = S(r, n);
|
|
171
|
+
return n["spread-last"] && g.forEach((x, E) => {
|
|
172
172
|
x.node.type === u.SpreadElement && g.push(g.splice(E, 1).at(0));
|
|
173
|
-
}), v(
|
|
173
|
+
}), v(c, r, g, p);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
});
|
|
@@ -178,7 +178,7 @@ const _ = "sort-array-includes", pe = k({
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
})
|
|
181
|
-
}), U = "sort-named-exports",
|
|
181
|
+
}), U = "sort-named-exports", de = A({
|
|
182
182
|
name: U,
|
|
183
183
|
meta: {
|
|
184
184
|
type: "suggestion",
|
|
@@ -193,15 +193,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
193
193
|
properties: {
|
|
194
194
|
type: {
|
|
195
195
|
enum: [
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
i.alphabetical,
|
|
197
|
+
i.natural,
|
|
198
|
+
i["line-length"]
|
|
199
199
|
],
|
|
200
|
-
default:
|
|
200
|
+
default: i.natural
|
|
201
201
|
},
|
|
202
202
|
order: {
|
|
203
|
-
enum: [
|
|
204
|
-
default:
|
|
203
|
+
enum: [d.asc, d.desc],
|
|
204
|
+
default: d.asc
|
|
205
205
|
},
|
|
206
206
|
"ignore-case": {
|
|
207
207
|
type: "boolean",
|
|
@@ -217,37 +217,37 @@ const _ = "sort-array-includes", pe = k({
|
|
|
217
217
|
},
|
|
218
218
|
defaultOptions: [
|
|
219
219
|
{
|
|
220
|
-
type:
|
|
221
|
-
order:
|
|
220
|
+
type: i.alphabetical,
|
|
221
|
+
order: d.asc
|
|
222
222
|
}
|
|
223
223
|
],
|
|
224
|
-
create: (
|
|
225
|
-
ExportNamedDeclaration: (
|
|
226
|
-
if (
|
|
227
|
-
let
|
|
228
|
-
type:
|
|
224
|
+
create: (t) => ({
|
|
225
|
+
ExportNamedDeclaration: (l) => {
|
|
226
|
+
if (l.specifiers.length > 1) {
|
|
227
|
+
let s = k(t.options.at(0), {
|
|
228
|
+
type: i.alphabetical,
|
|
229
229
|
"ignore-case": !1,
|
|
230
|
-
order:
|
|
231
|
-
}),
|
|
232
|
-
size:
|
|
230
|
+
order: d.asc
|
|
231
|
+
}), n = t.getSourceCode(), p = l.specifiers.map((r) => ({
|
|
232
|
+
size: N(r.range),
|
|
233
233
|
name: r.local.name,
|
|
234
234
|
node: r
|
|
235
235
|
}));
|
|
236
|
-
P(
|
|
237
|
-
j(r, e,
|
|
236
|
+
P(p, (r, e) => {
|
|
237
|
+
j(r, e, s) && t.report({
|
|
238
238
|
messageId: "unexpectedNamedExportsOrder",
|
|
239
239
|
data: {
|
|
240
240
|
left: r.name,
|
|
241
241
|
right: e.name
|
|
242
242
|
},
|
|
243
243
|
node: e.node,
|
|
244
|
-
fix: (o) => v(o,
|
|
244
|
+
fix: (o) => v(o, p, S(p, s), n)
|
|
245
245
|
});
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
})
|
|
250
|
-
}), z = "sort-named-imports",
|
|
250
|
+
}), z = "sort-named-imports", fe = A({
|
|
251
251
|
name: z,
|
|
252
252
|
meta: {
|
|
253
253
|
type: "suggestion",
|
|
@@ -262,15 +262,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
262
262
|
properties: {
|
|
263
263
|
type: {
|
|
264
264
|
enum: [
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
i.alphabetical,
|
|
266
|
+
i.natural,
|
|
267
|
+
i["line-length"]
|
|
268
268
|
],
|
|
269
|
-
default:
|
|
269
|
+
default: i.natural
|
|
270
270
|
},
|
|
271
271
|
order: {
|
|
272
|
-
enum: [
|
|
273
|
-
default:
|
|
272
|
+
enum: [d.asc, d.desc],
|
|
273
|
+
default: d.asc
|
|
274
274
|
},
|
|
275
275
|
"ignore-case": {
|
|
276
276
|
type: "boolean",
|
|
@@ -286,40 +286,40 @@ const _ = "sort-array-includes", pe = k({
|
|
|
286
286
|
},
|
|
287
287
|
defaultOptions: [
|
|
288
288
|
{
|
|
289
|
-
type:
|
|
290
|
-
order:
|
|
289
|
+
type: i.alphabetical,
|
|
290
|
+
order: d.asc
|
|
291
291
|
}
|
|
292
292
|
],
|
|
293
|
-
create: (
|
|
294
|
-
ImportDeclaration: (
|
|
295
|
-
let
|
|
296
|
-
({ type:
|
|
293
|
+
create: (t) => ({
|
|
294
|
+
ImportDeclaration: (l) => {
|
|
295
|
+
let s = l.specifiers.filter(
|
|
296
|
+
({ type: n }) => n === u.ImportSpecifier
|
|
297
297
|
);
|
|
298
|
-
if (
|
|
299
|
-
let
|
|
300
|
-
type:
|
|
298
|
+
if (s.length > 1) {
|
|
299
|
+
let n = k(t.options.at(0), {
|
|
300
|
+
type: i.alphabetical,
|
|
301
301
|
"ignore-case": !1,
|
|
302
|
-
order:
|
|
303
|
-
}),
|
|
304
|
-
size:
|
|
302
|
+
order: d.asc
|
|
303
|
+
}), p = t.getSourceCode(), r = s.map((e) => ({
|
|
304
|
+
size: N(e.range),
|
|
305
305
|
name: e.local.name,
|
|
306
306
|
node: e
|
|
307
307
|
}));
|
|
308
308
|
P(r, (e, o) => {
|
|
309
|
-
j(e, o,
|
|
309
|
+
j(e, o, n) && t.report({
|
|
310
310
|
messageId: "unexpectedNamedImportsOrder",
|
|
311
311
|
data: {
|
|
312
312
|
left: e.name,
|
|
313
313
|
right: o.name
|
|
314
314
|
},
|
|
315
315
|
node: o.node,
|
|
316
|
-
fix: (
|
|
316
|
+
fix: (a) => v(a, r, S(r, n), p)
|
|
317
317
|
});
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
})
|
|
322
|
-
}), D = "sort-object-types",
|
|
322
|
+
}), D = "sort-object-types", ue = A({
|
|
323
323
|
name: D,
|
|
324
324
|
meta: {
|
|
325
325
|
type: "suggestion",
|
|
@@ -334,15 +334,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
334
334
|
properties: {
|
|
335
335
|
type: {
|
|
336
336
|
enum: [
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
i.alphabetical,
|
|
338
|
+
i.natural,
|
|
339
|
+
i["line-length"]
|
|
340
340
|
],
|
|
341
|
-
default:
|
|
341
|
+
default: i.natural
|
|
342
342
|
},
|
|
343
343
|
order: {
|
|
344
|
-
enum: [
|
|
345
|
-
default:
|
|
344
|
+
enum: [d.asc, d.desc],
|
|
345
|
+
default: d.asc
|
|
346
346
|
},
|
|
347
347
|
"ignore-case": {
|
|
348
348
|
type: "boolean",
|
|
@@ -358,54 +358,54 @@ const _ = "sort-array-includes", pe = k({
|
|
|
358
358
|
},
|
|
359
359
|
defaultOptions: [
|
|
360
360
|
{
|
|
361
|
-
type:
|
|
362
|
-
order:
|
|
361
|
+
type: i.alphabetical,
|
|
362
|
+
order: d.asc
|
|
363
363
|
}
|
|
364
364
|
],
|
|
365
|
-
create: (
|
|
366
|
-
TSTypeLiteral: (
|
|
367
|
-
if (
|
|
368
|
-
let
|
|
369
|
-
type:
|
|
365
|
+
create: (t) => ({
|
|
366
|
+
TSTypeLiteral: (l) => {
|
|
367
|
+
if (l.members.length > 1) {
|
|
368
|
+
let s = k(t.options.at(0), {
|
|
369
|
+
type: i.alphabetical,
|
|
370
370
|
"ignore-case": !1,
|
|
371
|
-
order:
|
|
372
|
-
}),
|
|
371
|
+
order: d.asc
|
|
372
|
+
}), n = t.getSourceCode(), p = l.members.map((r) => {
|
|
373
373
|
var x, E;
|
|
374
|
-
let e, o =
|
|
374
|
+
let e, o = n.text.slice(r.range.at(0), r.range.at(1)), a = (y) => y.replace(/(,|;)$/, "");
|
|
375
375
|
if (r.type === u.TSPropertySignature)
|
|
376
|
-
r.key.type === u.Identifier ? { name: e } = r.key : r.key.type === u.Literal ? e = `${r.key.value}` : e =
|
|
376
|
+
r.key.type === u.Identifier ? { name: e } = r.key : r.key.type === u.Literal ? e = `${r.key.value}` : e = n.text.slice(
|
|
377
377
|
r.range.at(0),
|
|
378
378
|
(x = r.typeAnnotation) == null ? void 0 : x.range.at(0)
|
|
379
379
|
);
|
|
380
380
|
else if (r.type === u.TSIndexSignature) {
|
|
381
381
|
let y = ((E = r.typeAnnotation) == null ? void 0 : E.range.at(0)) ?? r.range.at(1);
|
|
382
|
-
e =
|
|
382
|
+
e = a(n.text.slice(r.range.at(0), y));
|
|
383
383
|
} else
|
|
384
|
-
e =
|
|
385
|
-
|
|
384
|
+
e = a(
|
|
385
|
+
n.text.slice(r.range.at(0), r.range.at(1))
|
|
386
386
|
);
|
|
387
387
|
let g = o.endsWith(";") || o.endsWith(",") ? 1 : 0;
|
|
388
388
|
return {
|
|
389
|
-
size:
|
|
389
|
+
size: N(r.range) - g,
|
|
390
390
|
node: r,
|
|
391
391
|
name: e
|
|
392
392
|
};
|
|
393
393
|
});
|
|
394
|
-
P(
|
|
395
|
-
j(r, e,
|
|
394
|
+
P(p, (r, e) => {
|
|
395
|
+
j(r, e, s) && t.report({
|
|
396
396
|
messageId: "unexpectedObjectTypesOrder",
|
|
397
397
|
data: {
|
|
398
398
|
left: I(r.name),
|
|
399
399
|
right: I(e.name)
|
|
400
400
|
},
|
|
401
401
|
node: e.node,
|
|
402
|
-
fix: (o) => v(o,
|
|
402
|
+
fix: (o) => v(o, p, S(p, s), n)
|
|
403
403
|
});
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
})
|
|
408
|
-
}), J = "sort-map-elements",
|
|
408
|
+
}), J = "sort-map-elements", ge = A({
|
|
409
409
|
name: J,
|
|
410
410
|
meta: {
|
|
411
411
|
type: "suggestion",
|
|
@@ -420,15 +420,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
420
420
|
properties: {
|
|
421
421
|
type: {
|
|
422
422
|
enum: [
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
423
|
+
i.alphabetical,
|
|
424
|
+
i.natural,
|
|
425
|
+
i["line-length"]
|
|
426
426
|
],
|
|
427
|
-
default:
|
|
427
|
+
default: i.natural
|
|
428
428
|
},
|
|
429
429
|
order: {
|
|
430
|
-
enum: [
|
|
431
|
-
default:
|
|
430
|
+
enum: [d.asc, d.desc],
|
|
431
|
+
default: d.asc
|
|
432
432
|
},
|
|
433
433
|
"ignore-case": {
|
|
434
434
|
type: "boolean",
|
|
@@ -444,46 +444,46 @@ const _ = "sort-array-includes", pe = k({
|
|
|
444
444
|
},
|
|
445
445
|
defaultOptions: [
|
|
446
446
|
{
|
|
447
|
-
type:
|
|
448
|
-
order:
|
|
447
|
+
type: i.alphabetical,
|
|
448
|
+
order: d.asc
|
|
449
449
|
}
|
|
450
450
|
],
|
|
451
|
-
create: (
|
|
452
|
-
NewExpression: (
|
|
453
|
-
if (
|
|
454
|
-
let [{ elements:
|
|
455
|
-
if (
|
|
456
|
-
let
|
|
457
|
-
type:
|
|
451
|
+
create: (t) => ({
|
|
452
|
+
NewExpression: (l) => {
|
|
453
|
+
if (l.callee.type === u.Identifier && l.callee.name === "Map" && l.arguments.length && l.arguments[0].type === u.ArrayExpression) {
|
|
454
|
+
let [{ elements: s }] = l.arguments;
|
|
455
|
+
if (s.length > 1) {
|
|
456
|
+
let n = k(t.options.at(0), {
|
|
457
|
+
type: i.alphabetical,
|
|
458
458
|
"ignore-case": !1,
|
|
459
|
-
order:
|
|
460
|
-
}),
|
|
461
|
-
|
|
459
|
+
order: d.asc
|
|
460
|
+
}), p = t.getSourceCode();
|
|
461
|
+
s.reduce(
|
|
462
462
|
(e, o) => (o === null || o.type === u.SpreadElement ? e.push([]) : e.at(-1).push(o), e),
|
|
463
463
|
[[]]
|
|
464
464
|
).forEach((e) => {
|
|
465
|
-
let o = e.map((
|
|
466
|
-
let
|
|
467
|
-
if (
|
|
468
|
-
let [g] =
|
|
469
|
-
g ? g.type === u.Literal ?
|
|
465
|
+
let o = e.map((a) => {
|
|
466
|
+
let c;
|
|
467
|
+
if (a.type === u.ArrayExpression) {
|
|
468
|
+
let [g] = a.elements;
|
|
469
|
+
g ? g.type === u.Literal ? c = g.raw : c = p.text.slice(...g.range) : c = `${g}`;
|
|
470
470
|
} else
|
|
471
|
-
|
|
471
|
+
c = p.text.slice(...a.range);
|
|
472
472
|
return {
|
|
473
|
-
size:
|
|
474
|
-
node:
|
|
475
|
-
name:
|
|
473
|
+
size: N(a.range),
|
|
474
|
+
node: a,
|
|
475
|
+
name: c
|
|
476
476
|
};
|
|
477
477
|
});
|
|
478
|
-
P(o, (
|
|
479
|
-
j(
|
|
478
|
+
P(o, (a, c) => {
|
|
479
|
+
j(a, c, n) && t.report({
|
|
480
480
|
messageId: "unexpectedMapElementsOrder",
|
|
481
481
|
data: {
|
|
482
|
-
left: I(
|
|
483
|
-
right: I(
|
|
482
|
+
left: I(a.name),
|
|
483
|
+
right: I(c.name)
|
|
484
484
|
},
|
|
485
|
-
node:
|
|
486
|
-
fix: (g) => v(g, o, S(o,
|
|
485
|
+
node: c.node,
|
|
486
|
+
fix: (g) => v(g, o, S(o, n), p)
|
|
487
487
|
});
|
|
488
488
|
});
|
|
489
489
|
});
|
|
@@ -491,7 +491,7 @@ const _ = "sort-array-includes", pe = k({
|
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
493
|
})
|
|
494
|
-
}), W = "sort-union-types",
|
|
494
|
+
}), W = "sort-union-types", me = A({
|
|
495
495
|
name: W,
|
|
496
496
|
meta: {
|
|
497
497
|
type: "suggestion",
|
|
@@ -506,15 +506,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
506
506
|
properties: {
|
|
507
507
|
type: {
|
|
508
508
|
enum: [
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
509
|
+
i.alphabetical,
|
|
510
|
+
i.natural,
|
|
511
|
+
i["line-length"]
|
|
512
512
|
],
|
|
513
|
-
default:
|
|
513
|
+
default: i.natural
|
|
514
514
|
},
|
|
515
515
|
order: {
|
|
516
|
-
enum: [
|
|
517
|
-
default:
|
|
516
|
+
enum: [d.asc, d.desc],
|
|
517
|
+
default: d.asc
|
|
518
518
|
},
|
|
519
519
|
"ignore-case": {
|
|
520
520
|
type: "boolean",
|
|
@@ -530,35 +530,35 @@ const _ = "sort-array-includes", pe = k({
|
|
|
530
530
|
},
|
|
531
531
|
defaultOptions: [
|
|
532
532
|
{
|
|
533
|
-
type:
|
|
534
|
-
order:
|
|
533
|
+
type: i.alphabetical,
|
|
534
|
+
order: d.asc
|
|
535
535
|
}
|
|
536
536
|
],
|
|
537
|
-
create: (
|
|
538
|
-
TSUnionType: (
|
|
539
|
-
let
|
|
540
|
-
type:
|
|
537
|
+
create: (t) => ({
|
|
538
|
+
TSUnionType: (l) => {
|
|
539
|
+
let s = t.getSourceCode(), n = k(t.options.at(0), {
|
|
540
|
+
type: i.alphabetical,
|
|
541
541
|
"ignore-case": !1,
|
|
542
|
-
order:
|
|
543
|
-
}),
|
|
544
|
-
name:
|
|
545
|
-
size:
|
|
542
|
+
order: d.asc
|
|
543
|
+
}), p = l.types.map((r) => ({
|
|
544
|
+
name: s.text.slice(...r.range),
|
|
545
|
+
size: N(r.range),
|
|
546
546
|
node: r
|
|
547
547
|
}));
|
|
548
|
-
P(
|
|
549
|
-
j(r, e,
|
|
548
|
+
P(p, (r, e) => {
|
|
549
|
+
j(r, e, n) && t.report({
|
|
550
550
|
messageId: "unexpectedUnionTypesOrder",
|
|
551
551
|
data: {
|
|
552
552
|
left: I(r.name),
|
|
553
553
|
right: I(e.name)
|
|
554
554
|
},
|
|
555
555
|
node: e.node,
|
|
556
|
-
fix: (o) => v(o,
|
|
556
|
+
fix: (o) => v(o, p, S(p, n), s)
|
|
557
557
|
});
|
|
558
558
|
});
|
|
559
559
|
}
|
|
560
560
|
})
|
|
561
|
-
}), X = "sort-interfaces",
|
|
561
|
+
}), X = "sort-interfaces", ye = A({
|
|
562
562
|
name: X,
|
|
563
563
|
meta: {
|
|
564
564
|
type: "suggestion",
|
|
@@ -573,15 +573,15 @@ const _ = "sort-array-includes", pe = k({
|
|
|
573
573
|
properties: {
|
|
574
574
|
type: {
|
|
575
575
|
enum: [
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
576
|
+
i.alphabetical,
|
|
577
|
+
i.natural,
|
|
578
|
+
i["line-length"]
|
|
579
579
|
],
|
|
580
|
-
default:
|
|
580
|
+
default: i.natural
|
|
581
581
|
},
|
|
582
582
|
order: {
|
|
583
|
-
enum: [
|
|
584
|
-
default:
|
|
583
|
+
enum: [d.asc, d.desc],
|
|
584
|
+
default: d.asc
|
|
585
585
|
},
|
|
586
586
|
"ignore-case": {
|
|
587
587
|
type: "boolean",
|
|
@@ -601,24 +601,24 @@ const _ = "sort-array-includes", pe = k({
|
|
|
601
601
|
},
|
|
602
602
|
defaultOptions: [
|
|
603
603
|
{
|
|
604
|
-
type:
|
|
605
|
-
order:
|
|
604
|
+
type: i.alphabetical,
|
|
605
|
+
order: d.asc
|
|
606
606
|
}
|
|
607
607
|
],
|
|
608
|
-
create: (
|
|
609
|
-
TSInterfaceDeclaration: (
|
|
610
|
-
if (
|
|
611
|
-
let
|
|
612
|
-
type:
|
|
608
|
+
create: (t) => ({
|
|
609
|
+
TSInterfaceDeclaration: (l) => {
|
|
610
|
+
if (l.body.body.length > 1) {
|
|
611
|
+
let s = k(t.options.at(0), {
|
|
612
|
+
type: i.alphabetical,
|
|
613
613
|
"ignore-case": !1,
|
|
614
|
-
order:
|
|
614
|
+
order: d.asc,
|
|
615
615
|
"ignore-pattern": []
|
|
616
616
|
});
|
|
617
|
-
if (!
|
|
618
|
-
(
|
|
617
|
+
if (!s["ignore-pattern"].some(
|
|
618
|
+
(n) => B(l.id.name, n)
|
|
619
619
|
)) {
|
|
620
|
-
let
|
|
621
|
-
var o,
|
|
620
|
+
let n = t.getSourceCode(), p = l.body.body.map((r) => {
|
|
621
|
+
var o, a, c;
|
|
622
622
|
let e;
|
|
623
623
|
if (r.type === u.TSPropertySignature)
|
|
624
624
|
if (r.key.type === u.Identifier)
|
|
@@ -627,30 +627,30 @@ const _ = "sort-array-includes", pe = k({
|
|
|
627
627
|
e = `${r.key.value}`;
|
|
628
628
|
else {
|
|
629
629
|
let g = ((o = r.typeAnnotation) == null ? void 0 : o.range.at(0)) ?? r.range.at(1) - (r.optional ? 1 : 0);
|
|
630
|
-
e =
|
|
630
|
+
e = n.text.slice(r.range.at(0), g);
|
|
631
631
|
}
|
|
632
632
|
else if (r.type === u.TSIndexSignature) {
|
|
633
|
-
let g = ((
|
|
634
|
-
e =
|
|
633
|
+
let g = ((a = r.typeAnnotation) == null ? void 0 : a.range.at(0)) ?? r.range.at(1);
|
|
634
|
+
e = n.text.slice(r.range.at(0), g);
|
|
635
635
|
} else {
|
|
636
|
-
let g = ((
|
|
637
|
-
e =
|
|
636
|
+
let g = ((c = r.returnType) == null ? void 0 : c.range.at(0)) ?? r.range.at(1);
|
|
637
|
+
e = n.text.slice(r.range.at(0), g);
|
|
638
638
|
}
|
|
639
639
|
return {
|
|
640
|
-
size:
|
|
640
|
+
size: N(r.range),
|
|
641
641
|
node: r,
|
|
642
642
|
name: e
|
|
643
643
|
};
|
|
644
644
|
});
|
|
645
|
-
P(
|
|
646
|
-
j(r, e,
|
|
645
|
+
P(p, (r, e) => {
|
|
646
|
+
j(r, e, s) && t.report({
|
|
647
647
|
messageId: "unexpectedInterfacePropertiesOrder",
|
|
648
648
|
data: {
|
|
649
649
|
left: I(r.name),
|
|
650
650
|
right: I(e.name)
|
|
651
651
|
},
|
|
652
652
|
node: e.node,
|
|
653
|
-
fix: (o) => v(o,
|
|
653
|
+
fix: (o) => v(o, p, S(p, s), n)
|
|
654
654
|
});
|
|
655
655
|
});
|
|
656
656
|
}
|
|
@@ -658,11 +658,11 @@ const _ = "sort-array-includes", pe = k({
|
|
|
658
658
|
}
|
|
659
659
|
})
|
|
660
660
|
});
|
|
661
|
-
let
|
|
662
|
-
let
|
|
663
|
-
return
|
|
661
|
+
let ee = (t, l) => t.reduce((s, n) => {
|
|
662
|
+
let p = l(n);
|
|
663
|
+
return p in s || (s[p] = []), s[p].push(n), s;
|
|
664
664
|
}, {});
|
|
665
|
-
const G = "sort-jsx-props",
|
|
665
|
+
const G = "sort-jsx-props", he = A({
|
|
666
666
|
name: G,
|
|
667
667
|
meta: {
|
|
668
668
|
type: "suggestion",
|
|
@@ -677,15 +677,15 @@ const G = "sort-jsx-props", ye = k({
|
|
|
677
677
|
properties: {
|
|
678
678
|
type: {
|
|
679
679
|
enum: [
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
680
|
+
i.alphabetical,
|
|
681
|
+
i.natural,
|
|
682
|
+
i["line-length"]
|
|
683
683
|
],
|
|
684
|
-
default:
|
|
684
|
+
default: i.natural
|
|
685
685
|
},
|
|
686
686
|
order: {
|
|
687
|
-
enum: [
|
|
688
|
-
default:
|
|
687
|
+
enum: [d.asc, d.desc],
|
|
688
|
+
default: d.asc
|
|
689
689
|
},
|
|
690
690
|
"always-on-top": {
|
|
691
691
|
type: "array",
|
|
@@ -729,82 +729,82 @@ const G = "sort-jsx-props", ye = k({
|
|
|
729
729
|
},
|
|
730
730
|
defaultOptions: [
|
|
731
731
|
{
|
|
732
|
-
type:
|
|
733
|
-
order:
|
|
732
|
+
type: i.alphabetical,
|
|
733
|
+
order: d.asc
|
|
734
734
|
}
|
|
735
735
|
],
|
|
736
|
-
create: (
|
|
737
|
-
JSXElement: (
|
|
738
|
-
if (
|
|
739
|
-
let
|
|
740
|
-
type:
|
|
736
|
+
create: (t) => ({
|
|
737
|
+
JSXElement: (l) => {
|
|
738
|
+
if (l.openingElement.attributes.length > 1) {
|
|
739
|
+
let s = k(t.options.at(0), {
|
|
740
|
+
type: i.alphabetical,
|
|
741
741
|
shorthand: "ignore",
|
|
742
742
|
multiline: "ignore",
|
|
743
743
|
callback: "ignore",
|
|
744
744
|
"always-on-top": [],
|
|
745
745
|
"ignore-case": !1,
|
|
746
|
-
order:
|
|
747
|
-
}),
|
|
748
|
-
|
|
746
|
+
order: d.asc
|
|
747
|
+
}), n = t.getSourceCode();
|
|
748
|
+
l.openingElement.attributes.reduce(
|
|
749
749
|
(r, e) => {
|
|
750
750
|
if (e.type === u.JSXSpreadAttribute)
|
|
751
751
|
return r.push([]), r;
|
|
752
752
|
let o = "ignore";
|
|
753
|
-
e.name.type === u.JSXIdentifier &&
|
|
754
|
-
let
|
|
753
|
+
e.name.type === u.JSXIdentifier && s["always-on-top"].includes(e.name.name) ? o = "exception" : (s.shorthand !== "ignore" && e.value === null && (o = s.shorthand), s.callback !== "ignore" && e.name.type === u.JSXIdentifier && e.name.name.indexOf("on") === 0 && e.value !== null ? o = s.callback : s.multiline !== "ignore" && e.loc.start.line !== e.loc.end.line && (o = s.multiline));
|
|
754
|
+
let a = {
|
|
755
755
|
name: e.name.type === u.JSXNamespacedName ? `${e.name.namespace.name}:${e.name.name.name}` : e.name.name,
|
|
756
|
-
size:
|
|
756
|
+
size: N(e.range),
|
|
757
757
|
node: e,
|
|
758
758
|
position: o
|
|
759
759
|
};
|
|
760
|
-
return r.at(-1).push(
|
|
760
|
+
return r.at(-1).push(a), r;
|
|
761
761
|
},
|
|
762
762
|
[[]]
|
|
763
763
|
).forEach((r) => {
|
|
764
764
|
P(r, (e, o) => {
|
|
765
|
-
let
|
|
765
|
+
let a;
|
|
766
766
|
if (e.position === "exception" && o.position === "exception")
|
|
767
|
-
|
|
767
|
+
a = s["always-on-top"].indexOf(e.name) > s["always-on-top"].indexOf(o.name);
|
|
768
768
|
else if (e.position === o.position)
|
|
769
|
-
|
|
769
|
+
a = j(e, o, s);
|
|
770
770
|
else {
|
|
771
|
-
let
|
|
771
|
+
let c = {
|
|
772
772
|
exception: 2,
|
|
773
773
|
first: 1,
|
|
774
774
|
ignore: 0,
|
|
775
775
|
last: -1
|
|
776
776
|
};
|
|
777
|
-
|
|
777
|
+
a = c[e.position] < c[o.position];
|
|
778
778
|
}
|
|
779
|
-
|
|
779
|
+
a && t.report({
|
|
780
780
|
messageId: "unexpectedJSXPropsOrder",
|
|
781
781
|
data: {
|
|
782
782
|
left: e.name,
|
|
783
783
|
right: o.name
|
|
784
784
|
},
|
|
785
785
|
node: o.node,
|
|
786
|
-
fix: (
|
|
787
|
-
let g =
|
|
786
|
+
fix: (c) => {
|
|
787
|
+
let g = ee(r, ({ position: y }) => y), x = (y) => y in g ? g[y] : [], E = [
|
|
788
788
|
x(
|
|
789
789
|
"exception"
|
|
790
790
|
/* exception */
|
|
791
791
|
).sort(
|
|
792
|
-
(y,
|
|
792
|
+
(y, f) => s["always-on-top"].indexOf(y.name) - s["always-on-top"].indexOf(f.name)
|
|
793
793
|
),
|
|
794
794
|
S(x(
|
|
795
795
|
"first"
|
|
796
796
|
/* first */
|
|
797
|
-
),
|
|
797
|
+
), s),
|
|
798
798
|
S(x(
|
|
799
799
|
"ignore"
|
|
800
800
|
/* ignore */
|
|
801
|
-
),
|
|
801
|
+
), s),
|
|
802
802
|
S(x(
|
|
803
803
|
"last"
|
|
804
804
|
/* last */
|
|
805
|
-
),
|
|
805
|
+
), s)
|
|
806
806
|
].flat();
|
|
807
|
-
return v(
|
|
807
|
+
return v(c, r, E, n);
|
|
808
808
|
}
|
|
809
809
|
});
|
|
810
810
|
});
|
|
@@ -813,15 +813,15 @@ const G = "sort-jsx-props", ye = k({
|
|
|
813
813
|
}
|
|
814
814
|
})
|
|
815
815
|
});
|
|
816
|
-
class
|
|
816
|
+
class te {
|
|
817
817
|
static get() {
|
|
818
|
-
return this._instance ? this._instance : (this._instance =
|
|
819
|
-
ie.readFileSync(
|
|
818
|
+
return this._instance ? this._instance : (this._instance = oe.parse(
|
|
819
|
+
ie.readFileSync(le.resolve(process.cwd(), "tsconfig.json"), "utf8")
|
|
820
820
|
), this._instance);
|
|
821
821
|
}
|
|
822
822
|
}
|
|
823
|
-
|
|
824
|
-
const K = "sort-imports",
|
|
823
|
+
Q(te, "_instance");
|
|
824
|
+
const K = "sort-imports", xe = A({
|
|
825
825
|
name: K,
|
|
826
826
|
meta: {
|
|
827
827
|
type: "suggestion",
|
|
@@ -836,15 +836,15 @@ const K = "sort-imports", he = k({
|
|
|
836
836
|
properties: {
|
|
837
837
|
type: {
|
|
838
838
|
enum: [
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
839
|
+
i.alphabetical,
|
|
840
|
+
i.natural,
|
|
841
|
+
i["line-length"]
|
|
842
842
|
],
|
|
843
|
-
default:
|
|
843
|
+
default: i.natural
|
|
844
844
|
},
|
|
845
845
|
order: {
|
|
846
|
-
enum: [
|
|
847
|
-
default:
|
|
846
|
+
enum: [d.asc, d.desc],
|
|
847
|
+
default: d.asc
|
|
848
848
|
},
|
|
849
849
|
"ignore-case": {
|
|
850
850
|
type: "boolean",
|
|
@@ -884,29 +884,29 @@ const K = "sort-imports", he = k({
|
|
|
884
884
|
},
|
|
885
885
|
defaultOptions: [
|
|
886
886
|
{
|
|
887
|
-
type:
|
|
888
|
-
order:
|
|
887
|
+
type: i.alphabetical,
|
|
888
|
+
order: d.asc
|
|
889
889
|
}
|
|
890
890
|
],
|
|
891
|
-
create: (
|
|
891
|
+
create: (t) => {
|
|
892
892
|
var o;
|
|
893
|
-
let
|
|
893
|
+
let l = k(t.options.at(0), {
|
|
894
894
|
"newlines-between": "always",
|
|
895
895
|
"internal-pattern": ["~/**"],
|
|
896
|
-
type:
|
|
896
|
+
type: i.alphabetical,
|
|
897
897
|
"read-tsconfig": !1,
|
|
898
|
-
order:
|
|
898
|
+
order: d.asc,
|
|
899
899
|
"ignore-case": !1,
|
|
900
900
|
groups: []
|
|
901
|
-
}),
|
|
902
|
-
if (
|
|
903
|
-
let
|
|
904
|
-
(o =
|
|
905
|
-
|
|
901
|
+
}), s = [];
|
|
902
|
+
if (l["read-tsconfig"]) {
|
|
903
|
+
let a = te.get();
|
|
904
|
+
(o = a.compilerOptions) != null && o.paths && Object.keys(a.compilerOptions.paths).forEach((c) => {
|
|
905
|
+
s.push(c);
|
|
906
906
|
});
|
|
907
907
|
}
|
|
908
|
-
let
|
|
909
|
-
let
|
|
908
|
+
let n = t.getSourceCode(), p = [], r = (a) => {
|
|
909
|
+
let c, g = (h) => [".less", ".scss", ".sass", ".styl", ".pcss", ".css", ".sss"].some(
|
|
910
910
|
(w) => h.endsWith(w)
|
|
911
911
|
), x = (h) => [
|
|
912
912
|
"./index.d.js",
|
|
@@ -916,48 +916,48 @@ const K = "sort-imports", he = k({
|
|
|
916
916
|
"./index",
|
|
917
917
|
"./",
|
|
918
918
|
"."
|
|
919
|
-
].includes(h), E = (h) => h.indexOf("..") === 0, y = (h) => h.indexOf("./") === 0,
|
|
920
|
-
!
|
|
921
|
-
}, m = (h) =>
|
|
922
|
-
(w) =>
|
|
923
|
-
) ||
|
|
924
|
-
return
|
|
925
|
-
}, e = (
|
|
926
|
-
let
|
|
927
|
-
|
|
928
|
-
size:
|
|
929
|
-
group: r(
|
|
930
|
-
name:
|
|
931
|
-
node:
|
|
919
|
+
].includes(h), E = (h) => h.indexOf("..") === 0, y = (h) => h.indexOf("./") === 0, f = (h) => {
|
|
920
|
+
!c && l.groups.flat().includes(h) && (c = h);
|
|
921
|
+
}, m = (h) => l["internal-pattern"].length && l["internal-pattern"].some(
|
|
922
|
+
(w) => B(h.source.value, w)
|
|
923
|
+
) || s.some((w) => B(h.source.value, w));
|
|
924
|
+
return a.importKind === "type" && (a.type === u.ImportDeclaration && (Z(a.source.value) && f("builtin-type"), m(a) && f("internal-type"), x(a.source.value) && f("index-type"), E(a.source.value) && f("parent-type"), y(a.source.value) && f("sibling-type")), f("type")), !c && a.type === u.ImportDeclaration && (Z(a.source.value) && f("builtin"), m(a) && f("internal"), g(a.source.value) && f("style"), a.specifiers.length === 0 && f("side-effect"), x(a.source.value) && f("index"), E(a.source.value) && f("parent"), y(a.source.value) && f("sibling"), f("external")), c ?? "unknown";
|
|
925
|
+
}, e = (a) => {
|
|
926
|
+
let c;
|
|
927
|
+
a.type === u.ImportDeclaration ? c = a.source.value : a.moduleReference.type === u.TSExternalModuleReference && a.moduleReference.expression.type === u.Literal ? c = `${a.moduleReference.expression.value}` : c = n.text.slice(...a.moduleReference.range), p.push({
|
|
928
|
+
size: N(a.range),
|
|
929
|
+
group: r(a),
|
|
930
|
+
name: c,
|
|
931
|
+
node: a
|
|
932
932
|
});
|
|
933
933
|
};
|
|
934
934
|
return {
|
|
935
935
|
TSImportEqualsDeclaration: e,
|
|
936
936
|
ImportDeclaration: e,
|
|
937
937
|
"Program:exit": () => {
|
|
938
|
-
let
|
|
939
|
-
for (let
|
|
940
|
-
let h =
|
|
938
|
+
let a = (y) => {
|
|
939
|
+
for (let f = 0, m = l.groups.length; f < m; f++) {
|
|
940
|
+
let h = l.groups[f];
|
|
941
941
|
if (y.group === h || Array.isArray(h) && h.includes(y.group))
|
|
942
|
-
return
|
|
942
|
+
return f;
|
|
943
943
|
}
|
|
944
|
-
return
|
|
945
|
-
},
|
|
944
|
+
return l.groups.length;
|
|
945
|
+
}, c = (y, f) => !!n.getTokensBetween(
|
|
946
946
|
y.node,
|
|
947
|
-
|
|
947
|
+
F(f.node, n) || f.node,
|
|
948
948
|
{
|
|
949
949
|
includeComments: !0
|
|
950
950
|
}
|
|
951
|
-
).length, g = (y,
|
|
951
|
+
).length, g = (y, f) => n.lines.slice(
|
|
952
952
|
y.node.loc.end.line,
|
|
953
|
-
|
|
954
|
-
).filter((h) => !h.trim().length).length, x = (y,
|
|
955
|
-
let m = [], h =
|
|
953
|
+
f.node.loc.start.line - 1
|
|
954
|
+
).filter((h) => !h.trim().length).length, x = (y, f) => {
|
|
955
|
+
let m = [], h = f.reduce(
|
|
956
956
|
(O, b) => {
|
|
957
|
-
let R =
|
|
957
|
+
let R = a(b);
|
|
958
958
|
return R in O ? O[R] = S(
|
|
959
959
|
[...O[R], b],
|
|
960
|
-
|
|
960
|
+
l
|
|
961
961
|
) : O[R] = [b], O;
|
|
962
962
|
},
|
|
963
963
|
{}
|
|
@@ -971,35 +971,35 @@ const K = "sort-imports", he = k({
|
|
|
971
971
|
return w.forEach((O, b) => {
|
|
972
972
|
if (m.push(
|
|
973
973
|
y.replaceTextRange(
|
|
974
|
-
T(
|
|
975
|
-
|
|
974
|
+
T(f.at(b).node, n),
|
|
975
|
+
n.text.slice(...T(O.node, n))
|
|
976
976
|
)
|
|
977
|
-
),
|
|
977
|
+
), l["newlines-between"] !== "ignore") {
|
|
978
978
|
let R = w.at(b + 1);
|
|
979
979
|
if (R) {
|
|
980
980
|
let L = g(
|
|
981
|
-
|
|
982
|
-
|
|
981
|
+
f.at(b),
|
|
982
|
+
f.at(b + 1)
|
|
983
983
|
);
|
|
984
|
-
(
|
|
984
|
+
(l["newlines-between"] === "always" && a(O) === a(R) && L !== 0 || l["newlines-between"] === "never" && L > 0) && m.push(
|
|
985
985
|
y.removeRange([
|
|
986
|
-
T(
|
|
987
|
-
T(
|
|
986
|
+
T(f.at(b).node, n).at(1),
|
|
987
|
+
T(f.at(b + 1).node, n).at(0) - 1
|
|
988
988
|
])
|
|
989
|
-
),
|
|
989
|
+
), l["newlines-between"] === "always" && L > 1 && m.push(
|
|
990
990
|
y.replaceTextRange(
|
|
991
991
|
[
|
|
992
|
-
T(
|
|
993
|
-
T(
|
|
992
|
+
T(f.at(b).node, n).at(1),
|
|
993
|
+
T(f.at(b + 1).node, n).at(
|
|
994
994
|
0
|
|
995
995
|
) - 1
|
|
996
996
|
],
|
|
997
997
|
`
|
|
998
998
|
`
|
|
999
999
|
)
|
|
1000
|
-
),
|
|
1000
|
+
), l["newlines-between"] === "always" && a(O) !== a(R) && L === 0 && m.push(
|
|
1001
1001
|
y.insertTextAfterRange(
|
|
1002
|
-
T(
|
|
1002
|
+
T(f.at(b).node, n),
|
|
1003
1003
|
`
|
|
1004
1004
|
`
|
|
1005
1005
|
)
|
|
@@ -1008,44 +1008,44 @@ const K = "sort-imports", he = k({
|
|
|
1008
1008
|
}
|
|
1009
1009
|
}), m;
|
|
1010
1010
|
};
|
|
1011
|
-
|
|
1012
|
-
(y,
|
|
1011
|
+
p.reduce(
|
|
1012
|
+
(y, f) => {
|
|
1013
1013
|
var h;
|
|
1014
1014
|
let m = (h = y.at(-1)) == null ? void 0 : h.at(-1);
|
|
1015
|
-
return m &&
|
|
1015
|
+
return m && c(m, f) ? y.push([f]) : y.at(-1).push(f), y;
|
|
1016
1016
|
},
|
|
1017
1017
|
[[]]
|
|
1018
1018
|
).forEach((y) => {
|
|
1019
|
-
P(y, (
|
|
1020
|
-
let h =
|
|
1021
|
-
!
|
|
1019
|
+
P(y, (f, m) => {
|
|
1020
|
+
let h = a(f), w = a(m), O = g(f, m);
|
|
1021
|
+
!c(f, m) && (h > w || h === w && j(f, m, l)) && t.report({
|
|
1022
1022
|
messageId: "unexpectedImportsOrder",
|
|
1023
1023
|
data: {
|
|
1024
|
-
left:
|
|
1024
|
+
left: f.name,
|
|
1025
1025
|
right: m.name
|
|
1026
1026
|
},
|
|
1027
1027
|
node: m.node,
|
|
1028
1028
|
fix: (b) => x(b, y)
|
|
1029
|
-
}),
|
|
1029
|
+
}), l["newlines-between"] === "never" && O > 0 && t.report({
|
|
1030
1030
|
messageId: "extraSpacingBetweenImports",
|
|
1031
1031
|
data: {
|
|
1032
|
-
left:
|
|
1032
|
+
left: f.name,
|
|
1033
1033
|
right: m.name
|
|
1034
1034
|
},
|
|
1035
1035
|
node: m.node,
|
|
1036
1036
|
fix: (b) => x(b, y)
|
|
1037
|
-
}),
|
|
1037
|
+
}), l["newlines-between"] === "always" && (h < w && O === 0 ? t.report({
|
|
1038
1038
|
messageId: "missedSpacingBetweenImports",
|
|
1039
1039
|
data: {
|
|
1040
|
-
left:
|
|
1040
|
+
left: f.name,
|
|
1041
1041
|
right: m.name
|
|
1042
1042
|
},
|
|
1043
1043
|
node: m.node,
|
|
1044
1044
|
fix: (b) => x(b, y)
|
|
1045
|
-
}) : (O > 1 || h === w && O > 0) &&
|
|
1045
|
+
}) : (O > 1 || h === w && O > 0) && t.report({
|
|
1046
1046
|
messageId: "extraSpacingBetweenImports",
|
|
1047
1047
|
data: {
|
|
1048
|
-
left:
|
|
1048
|
+
left: f.name,
|
|
1049
1049
|
right: m.name
|
|
1050
1050
|
},
|
|
1051
1051
|
node: m.node,
|
|
@@ -1056,7 +1056,7 @@ const K = "sort-imports", he = k({
|
|
|
1056
1056
|
}
|
|
1057
1057
|
};
|
|
1058
1058
|
}
|
|
1059
|
-
}), V = "sort-classes",
|
|
1059
|
+
}), V = "sort-classes", be = A({
|
|
1060
1060
|
name: V,
|
|
1061
1061
|
meta: {
|
|
1062
1062
|
type: "suggestion",
|
|
@@ -1071,19 +1071,19 @@ const K = "sort-imports", he = k({
|
|
|
1071
1071
|
properties: {
|
|
1072
1072
|
type: {
|
|
1073
1073
|
enum: [
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1074
|
+
i.alphabetical,
|
|
1075
|
+
i.natural,
|
|
1076
|
+
i["line-length"]
|
|
1077
1077
|
],
|
|
1078
|
-
default:
|
|
1078
|
+
default: i.natural
|
|
1079
1079
|
},
|
|
1080
1080
|
"ignore-case": {
|
|
1081
1081
|
type: "boolean",
|
|
1082
1082
|
default: !1
|
|
1083
1083
|
},
|
|
1084
1084
|
order: {
|
|
1085
|
-
enum: [
|
|
1086
|
-
default:
|
|
1085
|
+
enum: [d.asc, d.desc],
|
|
1086
|
+
default: d.asc
|
|
1087
1087
|
},
|
|
1088
1088
|
groups: {
|
|
1089
1089
|
type: "array",
|
|
@@ -1099,45 +1099,45 @@ const K = "sort-imports", he = k({
|
|
|
1099
1099
|
},
|
|
1100
1100
|
defaultOptions: [
|
|
1101
1101
|
{
|
|
1102
|
-
type:
|
|
1103
|
-
order:
|
|
1102
|
+
type: i.alphabetical,
|
|
1103
|
+
order: d.asc
|
|
1104
1104
|
}
|
|
1105
1105
|
],
|
|
1106
|
-
create: (
|
|
1107
|
-
ClassBody: (
|
|
1108
|
-
if (
|
|
1109
|
-
let
|
|
1110
|
-
type:
|
|
1111
|
-
order:
|
|
1106
|
+
create: (t) => ({
|
|
1107
|
+
ClassBody: (l) => {
|
|
1108
|
+
if (l.body.length > 1) {
|
|
1109
|
+
let s = k(t.options.at(0), {
|
|
1110
|
+
type: i.alphabetical,
|
|
1111
|
+
order: d.asc,
|
|
1112
1112
|
"ignore-case": !1,
|
|
1113
1113
|
groups: ["property", "constructor", "method", "unknown"]
|
|
1114
|
-
}),
|
|
1114
|
+
}), n = t.getSourceCode(), p = l.body.map((e) => {
|
|
1115
1115
|
var g;
|
|
1116
|
-
let o,
|
|
1117
|
-
e.type === u.StaticBlock ?
|
|
1116
|
+
let o, a;
|
|
1117
|
+
e.type === u.StaticBlock ? a = "static" : e.type === u.TSIndexSignature ? a = n.text.slice(
|
|
1118
1118
|
e.range.at(0),
|
|
1119
1119
|
((g = e.typeAnnotation) == null ? void 0 : g.range.at(0)) ?? e.range.at(1)
|
|
1120
|
-
) : e.key.type === u.Identifier ? { name:
|
|
1121
|
-
let
|
|
1122
|
-
!o &&
|
|
1120
|
+
) : e.key.type === u.Identifier ? { name: a } = e.key : a = n.text.slice(...e.key.range);
|
|
1121
|
+
let c = (x) => {
|
|
1122
|
+
!o && s.groups.flat().includes(x) && (o = x);
|
|
1123
1123
|
};
|
|
1124
|
-
return e.type === u.MethodDefinition ? (e.kind === "constructor" &&
|
|
1125
|
-
size:
|
|
1124
|
+
return e.type === u.MethodDefinition ? (e.kind === "constructor" && c("constructor"), e.static && c("static-method"), e.accessibility === "private" && c("private-method"), c("method")) : e.type === u.PropertyDefinition && (e.static && c("static-property"), e.accessibility === "private" && c("private-property"), c("property")), {
|
|
1125
|
+
size: N(e.range),
|
|
1126
1126
|
group: o ?? "unknown",
|
|
1127
1127
|
node: e,
|
|
1128
|
-
name:
|
|
1128
|
+
name: a
|
|
1129
1129
|
};
|
|
1130
1130
|
}), r = (e) => {
|
|
1131
|
-
for (let o = 0,
|
|
1132
|
-
let
|
|
1133
|
-
if (e.group ===
|
|
1131
|
+
for (let o = 0, a = s.groups.length; o < a; o++) {
|
|
1132
|
+
let c = s.groups[o];
|
|
1133
|
+
if (e.group === c || Array.isArray(c) && c.includes(e.group))
|
|
1134
1134
|
return o;
|
|
1135
1135
|
}
|
|
1136
|
-
return
|
|
1136
|
+
return s.groups.length;
|
|
1137
1137
|
};
|
|
1138
|
-
P(
|
|
1139
|
-
let
|
|
1140
|
-
(
|
|
1138
|
+
P(p, (e, o) => {
|
|
1139
|
+
let a = r(e), c = r(o);
|
|
1140
|
+
(a > c || a === c && j(e, o, s)) && t.report({
|
|
1141
1141
|
messageId: "unexpectedClassesOrder",
|
|
1142
1142
|
data: {
|
|
1143
1143
|
left: I(e.name),
|
|
@@ -1145,28 +1145,28 @@ const K = "sort-imports", he = k({
|
|
|
1145
1145
|
},
|
|
1146
1146
|
node: o.node,
|
|
1147
1147
|
fix: (g) => {
|
|
1148
|
-
let x = [], E =
|
|
1149
|
-
(
|
|
1148
|
+
let x = [], E = p.reduce(
|
|
1149
|
+
(f, m) => {
|
|
1150
1150
|
let h = r(m);
|
|
1151
|
-
return h in
|
|
1152
|
-
[...
|
|
1153
|
-
|
|
1154
|
-
) :
|
|
1151
|
+
return h in f ? f[h] = S(
|
|
1152
|
+
[...f[h], m],
|
|
1153
|
+
s
|
|
1154
|
+
) : f[h] = [m], f;
|
|
1155
1155
|
},
|
|
1156
1156
|
{}
|
|
1157
1157
|
);
|
|
1158
1158
|
return Object.keys(E).sort().reduce(
|
|
1159
|
-
(
|
|
1160
|
-
...
|
|
1159
|
+
(f, m) => [
|
|
1160
|
+
...f,
|
|
1161
1161
|
...E[m]
|
|
1162
1162
|
],
|
|
1163
1163
|
[]
|
|
1164
|
-
).forEach((
|
|
1164
|
+
).forEach((f, m) => {
|
|
1165
1165
|
x.push(
|
|
1166
1166
|
g.replaceTextRange(
|
|
1167
|
-
T(
|
|
1168
|
-
|
|
1169
|
-
...T(
|
|
1167
|
+
T(p.at(m).node, n),
|
|
1168
|
+
n.text.slice(
|
|
1169
|
+
...T(f.node, n)
|
|
1170
1170
|
)
|
|
1171
1171
|
)
|
|
1172
1172
|
);
|
|
@@ -1177,7 +1177,7 @@ const K = "sort-imports", he = k({
|
|
|
1177
1177
|
}
|
|
1178
1178
|
}
|
|
1179
1179
|
})
|
|
1180
|
-
}), Y = "sort-objects",
|
|
1180
|
+
}), Y = "sort-objects", Ee = A({
|
|
1181
1181
|
name: Y,
|
|
1182
1182
|
meta: {
|
|
1183
1183
|
type: "suggestion",
|
|
@@ -1192,15 +1192,15 @@ const K = "sort-imports", he = k({
|
|
|
1192
1192
|
properties: {
|
|
1193
1193
|
type: {
|
|
1194
1194
|
enum: [
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1195
|
+
i.alphabetical,
|
|
1196
|
+
i.natural,
|
|
1197
|
+
i["line-length"]
|
|
1198
1198
|
],
|
|
1199
|
-
default:
|
|
1199
|
+
default: i.natural
|
|
1200
1200
|
},
|
|
1201
1201
|
order: {
|
|
1202
|
-
enum: [
|
|
1203
|
-
default:
|
|
1202
|
+
enum: [d.asc, d.desc],
|
|
1203
|
+
default: d.asc
|
|
1204
1204
|
},
|
|
1205
1205
|
"ignore-case": {
|
|
1206
1206
|
type: "boolean",
|
|
@@ -1220,81 +1220,81 @@ const K = "sort-imports", he = k({
|
|
|
1220
1220
|
},
|
|
1221
1221
|
defaultOptions: [
|
|
1222
1222
|
{
|
|
1223
|
-
type:
|
|
1224
|
-
order:
|
|
1223
|
+
type: i.alphabetical,
|
|
1224
|
+
order: d.asc
|
|
1225
1225
|
}
|
|
1226
1226
|
],
|
|
1227
|
-
create: (
|
|
1228
|
-
let
|
|
1229
|
-
if (
|
|
1230
|
-
let
|
|
1231
|
-
type:
|
|
1227
|
+
create: (t) => {
|
|
1228
|
+
let l = (s) => {
|
|
1229
|
+
if (s.properties.length > 1) {
|
|
1230
|
+
let n = k(t.options.at(0), {
|
|
1231
|
+
type: i.alphabetical,
|
|
1232
1232
|
"ignore-case": !1,
|
|
1233
|
-
order:
|
|
1233
|
+
order: d.asc,
|
|
1234
1234
|
"always-on-top": []
|
|
1235
|
-
}),
|
|
1235
|
+
}), p = t.getSourceCode();
|
|
1236
1236
|
((e) => e.reduce(
|
|
1237
|
-
(o,
|
|
1238
|
-
if (
|
|
1237
|
+
(o, a) => {
|
|
1238
|
+
if (a.type === u.SpreadElement || a.type === u.RestElement)
|
|
1239
1239
|
return o.push([]), o;
|
|
1240
|
-
let
|
|
1241
|
-
if (
|
|
1242
|
-
let y = (
|
|
1243
|
-
|
|
1240
|
+
let c, g = "ignore", x = [];
|
|
1241
|
+
if (a.key.type === u.Identifier ? { name: c } = a.key : a.key.type === u.Literal ? c = `${a.key.value}` : c = p.text.slice(...a.key.range), a.key.type === u.Identifier && n["always-on-top"].includes(a.key.name) && (g = "exception"), a.value.type === u.AssignmentPattern) {
|
|
1242
|
+
let y = (f, m) => {
|
|
1243
|
+
f.right.type === u.Identifier && x.push(f.right.name), !m && f.left.type === u.Identifier && x.push(f.left.name);
|
|
1244
1244
|
let h = (w) => {
|
|
1245
1245
|
w.right.type === u.Identifier && x.push(w.right.name), w.left.type === u.BinaryExpression && y(w.left, !1);
|
|
1246
1246
|
};
|
|
1247
|
-
|
|
1247
|
+
f.right.type === u.BinaryExpression && h(f.right);
|
|
1248
1248
|
};
|
|
1249
|
-
y(
|
|
1249
|
+
y(a.value, !0);
|
|
1250
1250
|
}
|
|
1251
1251
|
let E = {
|
|
1252
|
-
size:
|
|
1252
|
+
size: N(a.range),
|
|
1253
1253
|
dependencies: x,
|
|
1254
|
-
node:
|
|
1254
|
+
node: a,
|
|
1255
1255
|
position: g,
|
|
1256
|
-
name:
|
|
1256
|
+
name: c
|
|
1257
1257
|
};
|
|
1258
1258
|
return o.at(-1).push(E), o;
|
|
1259
1259
|
},
|
|
1260
1260
|
[[]]
|
|
1261
|
-
))(
|
|
1262
|
-
P(e, (o,
|
|
1263
|
-
let
|
|
1264
|
-
if (o.position === "exception" &&
|
|
1265
|
-
|
|
1266
|
-
else if (o.position ===
|
|
1267
|
-
|
|
1261
|
+
))(s.properties).forEach((e) => {
|
|
1262
|
+
P(e, (o, a) => {
|
|
1263
|
+
let c;
|
|
1264
|
+
if (o.position === "exception" && a.position === "exception")
|
|
1265
|
+
c = n["always-on-top"].indexOf(o.name) > n["always-on-top"].indexOf(a.name);
|
|
1266
|
+
else if (o.position === a.position)
|
|
1267
|
+
c = j(o, a, n);
|
|
1268
1268
|
else {
|
|
1269
1269
|
let g = {
|
|
1270
1270
|
exception: 1,
|
|
1271
1271
|
ignore: 0
|
|
1272
1272
|
};
|
|
1273
|
-
|
|
1273
|
+
c = g[o.position] < g[a.position];
|
|
1274
1274
|
}
|
|
1275
|
-
if (
|
|
1275
|
+
if (c) {
|
|
1276
1276
|
let g = (x) => {
|
|
1277
|
-
let E =
|
|
1277
|
+
let E = ee(e, ({ position: m }) => m), y = (m) => m in E ? E[m] : [], f = [
|
|
1278
1278
|
y(
|
|
1279
1279
|
"exception"
|
|
1280
1280
|
/* exception */
|
|
1281
1281
|
).sort(
|
|
1282
|
-
(m, h) =>
|
|
1282
|
+
(m, h) => n["always-on-top"].indexOf(m.name) - n["always-on-top"].indexOf(h.name)
|
|
1283
1283
|
),
|
|
1284
1284
|
S(y(
|
|
1285
1285
|
"ignore"
|
|
1286
1286
|
/* ignore */
|
|
1287
|
-
),
|
|
1287
|
+
), n)
|
|
1288
1288
|
].flat();
|
|
1289
|
-
return v(x, e,
|
|
1289
|
+
return v(x, e, f, p);
|
|
1290
1290
|
};
|
|
1291
|
-
|
|
1291
|
+
t.report({
|
|
1292
1292
|
messageId: "unexpectedObjectsOrder",
|
|
1293
1293
|
data: {
|
|
1294
1294
|
left: I(o.name),
|
|
1295
|
-
right: I(
|
|
1295
|
+
right: I(a.name)
|
|
1296
1296
|
},
|
|
1297
|
-
node:
|
|
1297
|
+
node: a.node,
|
|
1298
1298
|
fix: g
|
|
1299
1299
|
});
|
|
1300
1300
|
}
|
|
@@ -1303,12 +1303,90 @@ const K = "sort-imports", he = k({
|
|
|
1303
1303
|
}
|
|
1304
1304
|
};
|
|
1305
1305
|
return {
|
|
1306
|
-
ObjectExpression:
|
|
1307
|
-
ObjectPattern:
|
|
1306
|
+
ObjectExpression: l,
|
|
1307
|
+
ObjectPattern: l
|
|
1308
1308
|
};
|
|
1309
1309
|
}
|
|
1310
|
-
}), q = "sort-
|
|
1310
|
+
}), q = "sort-exports", we = A({
|
|
1311
1311
|
name: q,
|
|
1312
|
+
meta: {
|
|
1313
|
+
type: "suggestion",
|
|
1314
|
+
docs: {
|
|
1315
|
+
description: "enforce sorted exports",
|
|
1316
|
+
recommended: !1
|
|
1317
|
+
},
|
|
1318
|
+
fixable: "code",
|
|
1319
|
+
schema: [
|
|
1320
|
+
{
|
|
1321
|
+
type: "object",
|
|
1322
|
+
properties: {
|
|
1323
|
+
type: {
|
|
1324
|
+
enum: [
|
|
1325
|
+
i.alphabetical,
|
|
1326
|
+
i.natural,
|
|
1327
|
+
i["line-length"]
|
|
1328
|
+
],
|
|
1329
|
+
default: i.natural
|
|
1330
|
+
},
|
|
1331
|
+
order: {
|
|
1332
|
+
enum: [d.asc, d.desc],
|
|
1333
|
+
default: d.asc
|
|
1334
|
+
},
|
|
1335
|
+
"ignore-case": {
|
|
1336
|
+
type: "boolean",
|
|
1337
|
+
default: !1
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
additionalProperties: !1
|
|
1341
|
+
}
|
|
1342
|
+
],
|
|
1343
|
+
messages: {
|
|
1344
|
+
unexpectedExportsOrder: 'Expected "{{right}}" to come before "{{left}}"'
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
defaultOptions: [
|
|
1348
|
+
{
|
|
1349
|
+
type: i.alphabetical,
|
|
1350
|
+
order: d.asc
|
|
1351
|
+
}
|
|
1352
|
+
],
|
|
1353
|
+
create: (t) => {
|
|
1354
|
+
let l = k(t.options.at(0), {
|
|
1355
|
+
type: i.alphabetical,
|
|
1356
|
+
order: d.asc,
|
|
1357
|
+
"ignore-case": !1
|
|
1358
|
+
}), s = [[]], n = (p) => {
|
|
1359
|
+
p.type === u.ExportAllDeclaration && p.exported === null ? s.push([]) : s.at(-1).push({
|
|
1360
|
+
size: N(p.range),
|
|
1361
|
+
name: p.source.value,
|
|
1362
|
+
node: p
|
|
1363
|
+
});
|
|
1364
|
+
};
|
|
1365
|
+
return {
|
|
1366
|
+
ExportAllDeclaration: n,
|
|
1367
|
+
ExportNamedDeclaration: (p) => {
|
|
1368
|
+
p.source !== null && n(p);
|
|
1369
|
+
},
|
|
1370
|
+
"Program:exit": () => {
|
|
1371
|
+
let p = t.getSourceCode();
|
|
1372
|
+
s.forEach((r) => {
|
|
1373
|
+
P(r, (e, o) => {
|
|
1374
|
+
j(e, o, l) && t.report({
|
|
1375
|
+
messageId: "unexpectedExportsOrder",
|
|
1376
|
+
data: {
|
|
1377
|
+
left: e.name,
|
|
1378
|
+
right: o.name
|
|
1379
|
+
},
|
|
1380
|
+
node: o.node,
|
|
1381
|
+
fix: (a) => v(a, r, S(r, l), p)
|
|
1382
|
+
});
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
}), H = "sort-enums", Oe = A({
|
|
1389
|
+
name: H,
|
|
1312
1390
|
meta: {
|
|
1313
1391
|
type: "suggestion",
|
|
1314
1392
|
docs: {
|
|
@@ -1322,19 +1400,19 @@ const K = "sort-imports", he = k({
|
|
|
1322
1400
|
properties: {
|
|
1323
1401
|
type: {
|
|
1324
1402
|
enum: [
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1403
|
+
i.alphabetical,
|
|
1404
|
+
i.natural,
|
|
1405
|
+
i["line-length"]
|
|
1328
1406
|
],
|
|
1329
|
-
default:
|
|
1407
|
+
default: i.natural
|
|
1330
1408
|
},
|
|
1331
1409
|
"ignore-case": {
|
|
1332
1410
|
type: "boolean",
|
|
1333
1411
|
default: !1
|
|
1334
1412
|
},
|
|
1335
1413
|
order: {
|
|
1336
|
-
enum: [
|
|
1337
|
-
default:
|
|
1414
|
+
enum: [d.asc, d.desc],
|
|
1415
|
+
default: d.asc
|
|
1338
1416
|
}
|
|
1339
1417
|
},
|
|
1340
1418
|
additionalProperties: !1
|
|
@@ -1346,39 +1424,39 @@ const K = "sort-imports", he = k({
|
|
|
1346
1424
|
},
|
|
1347
1425
|
defaultOptions: [
|
|
1348
1426
|
{
|
|
1349
|
-
type:
|
|
1350
|
-
order:
|
|
1427
|
+
type: i.alphabetical,
|
|
1428
|
+
order: d.asc
|
|
1351
1429
|
}
|
|
1352
1430
|
],
|
|
1353
|
-
create: (
|
|
1354
|
-
TSEnumDeclaration: (
|
|
1355
|
-
if (
|
|
1356
|
-
let
|
|
1357
|
-
type:
|
|
1358
|
-
order:
|
|
1431
|
+
create: (t) => ({
|
|
1432
|
+
TSEnumDeclaration: (l) => {
|
|
1433
|
+
if (l.members.length > 1 && l.members.some(({ initializer: s }) => s)) {
|
|
1434
|
+
let s = k(t.options.at(0), {
|
|
1435
|
+
type: i.alphabetical,
|
|
1436
|
+
order: d.asc,
|
|
1359
1437
|
"ignore-case": !1
|
|
1360
|
-
}),
|
|
1361
|
-
name: r.id.type === u.Literal ? `${r.id.value}` : `${
|
|
1362
|
-
size:
|
|
1438
|
+
}), n = t.getSourceCode(), p = l.members.map((r) => ({
|
|
1439
|
+
name: r.id.type === u.Literal ? `${r.id.value}` : `${n.text.slice(...r.id.range)}`,
|
|
1440
|
+
size: N(r.range),
|
|
1363
1441
|
node: r
|
|
1364
1442
|
}));
|
|
1365
|
-
P(
|
|
1366
|
-
j(r, e,
|
|
1443
|
+
P(p, (r, e) => {
|
|
1444
|
+
j(r, e, s) && t.report({
|
|
1367
1445
|
messageId: "unexpectedEnumsOrder",
|
|
1368
1446
|
data: {
|
|
1369
1447
|
left: I(r.name),
|
|
1370
1448
|
right: I(e.name)
|
|
1371
1449
|
},
|
|
1372
1450
|
node: e.node,
|
|
1373
|
-
fix: (o) => v(o,
|
|
1451
|
+
fix: (o) => v(o, p, S(p, s), n)
|
|
1374
1452
|
});
|
|
1375
1453
|
});
|
|
1376
1454
|
}
|
|
1377
1455
|
}
|
|
1378
1456
|
})
|
|
1379
|
-
}),
|
|
1380
|
-
let
|
|
1381
|
-
let
|
|
1457
|
+
}), Ie = "eslint-plugin-perfectionist";
|
|
1458
|
+
let M = (t) => {
|
|
1459
|
+
let l = {
|
|
1382
1460
|
[K]: [
|
|
1383
1461
|
"error",
|
|
1384
1462
|
{
|
|
@@ -1439,51 +1517,53 @@ let B = (a) => {
|
|
|
1439
1517
|
[J]: ["error"],
|
|
1440
1518
|
[W]: ["error"],
|
|
1441
1519
|
[X]: ["error"],
|
|
1442
|
-
[q]: ["error"]
|
|
1520
|
+
[q]: ["error"],
|
|
1521
|
+
[H]: ["error"]
|
|
1443
1522
|
};
|
|
1444
1523
|
return {
|
|
1445
1524
|
rules: Object.fromEntries(
|
|
1446
|
-
Object.entries(
|
|
1447
|
-
`perfectionist/${
|
|
1448
|
-
[
|
|
1525
|
+
Object.entries(l).map(([s, [n, p = {}]]) => [
|
|
1526
|
+
`perfectionist/${s}`,
|
|
1527
|
+
[n, Object.assign(p, t)]
|
|
1449
1528
|
])
|
|
1450
1529
|
),
|
|
1451
1530
|
plugins: ["perfectionist"]
|
|
1452
1531
|
};
|
|
1453
1532
|
};
|
|
1454
|
-
const
|
|
1533
|
+
const Ce = {
|
|
1455
1534
|
rules: {
|
|
1456
|
-
[_]:
|
|
1457
|
-
[V]:
|
|
1458
|
-
[
|
|
1459
|
-
[
|
|
1460
|
-
[
|
|
1461
|
-
[
|
|
1462
|
-
[
|
|
1463
|
-
[
|
|
1464
|
-
[
|
|
1465
|
-
[
|
|
1466
|
-
[
|
|
1467
|
-
[
|
|
1535
|
+
[_]: ce,
|
|
1536
|
+
[V]: be,
|
|
1537
|
+
[H]: Oe,
|
|
1538
|
+
[q]: we,
|
|
1539
|
+
[K]: xe,
|
|
1540
|
+
[X]: ye,
|
|
1541
|
+
[G]: he,
|
|
1542
|
+
[J]: ge,
|
|
1543
|
+
[U]: de,
|
|
1544
|
+
[z]: fe,
|
|
1545
|
+
[D]: ue,
|
|
1546
|
+
[Y]: Ee,
|
|
1547
|
+
[W]: me
|
|
1468
1548
|
},
|
|
1469
1549
|
configs: {
|
|
1470
|
-
"recommended-alphabetical":
|
|
1471
|
-
type:
|
|
1472
|
-
order:
|
|
1550
|
+
"recommended-alphabetical": M({
|
|
1551
|
+
type: i.alphabetical,
|
|
1552
|
+
order: d.asc,
|
|
1473
1553
|
"ignore-case": !1
|
|
1474
1554
|
}),
|
|
1475
|
-
"recommended-natural":
|
|
1476
|
-
type:
|
|
1477
|
-
order:
|
|
1555
|
+
"recommended-natural": M({
|
|
1556
|
+
type: i.natural,
|
|
1557
|
+
order: d.asc,
|
|
1478
1558
|
"ignore-case": !1
|
|
1479
1559
|
}),
|
|
1480
|
-
"recommended-line-length":
|
|
1481
|
-
type:
|
|
1482
|
-
order:
|
|
1560
|
+
"recommended-line-length": M({
|
|
1561
|
+
type: i["line-length"],
|
|
1562
|
+
order: d.desc
|
|
1483
1563
|
})
|
|
1484
1564
|
},
|
|
1485
|
-
name:
|
|
1565
|
+
name: Ie
|
|
1486
1566
|
};
|
|
1487
1567
|
export {
|
|
1488
|
-
|
|
1568
|
+
Ce as default
|
|
1489
1569
|
};
|