@isentinel/eslint-config 1.1.2 → 1.2.2
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/README.md +65 -45
- package/dist/{chunk-VXR6SE7R.js → chunk-2HV5XKT7.js} +2 -2
- package/dist/cli.js +108 -118
- package/dist/eslint-plugin-simple-import-sort-FWMVSWU4.js +808 -0
- package/dist/index.d.ts +92 -58
- package/dist/index.js +3530 -1042
- package/package.json +9 -9
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
init_esm_shims
|
|
4
|
+
} from "./chunk-2HV5XKT7.js";
|
|
5
|
+
|
|
6
|
+
// node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/shared.js
|
|
7
|
+
var require_shared = __commonJS({
|
|
8
|
+
"node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/shared.js"(exports, module) {
|
|
9
|
+
"use strict";
|
|
10
|
+
init_esm_shims();
|
|
11
|
+
function extractChunks(parentNode, isPartOfChunk) {
|
|
12
|
+
const chunks = [];
|
|
13
|
+
let chunk = [];
|
|
14
|
+
let lastNode = void 0;
|
|
15
|
+
for (const node of parentNode.body) {
|
|
16
|
+
const result = isPartOfChunk(node, lastNode);
|
|
17
|
+
switch (result) {
|
|
18
|
+
case "PartOfChunk":
|
|
19
|
+
chunk.push(node);
|
|
20
|
+
break;
|
|
21
|
+
case "PartOfNewChunk":
|
|
22
|
+
if (chunk.length > 0) {
|
|
23
|
+
chunks.push(chunk);
|
|
24
|
+
}
|
|
25
|
+
chunk = [node];
|
|
26
|
+
break;
|
|
27
|
+
case "NotPartOfChunk":
|
|
28
|
+
if (chunk.length > 0) {
|
|
29
|
+
chunks.push(chunk);
|
|
30
|
+
chunk = [];
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
/* v8 ignore start */
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown chunk result: ${result}`);
|
|
36
|
+
}
|
|
37
|
+
lastNode = node;
|
|
38
|
+
}
|
|
39
|
+
if (chunk.length > 0) {
|
|
40
|
+
chunks.push(chunk);
|
|
41
|
+
}
|
|
42
|
+
return chunks;
|
|
43
|
+
}
|
|
44
|
+
function maybeReportSorting(context, sorted, start, end) {
|
|
45
|
+
const sourceCode = getSourceCode(context);
|
|
46
|
+
const original = sourceCode.getText().slice(start, end);
|
|
47
|
+
if (original !== sorted) {
|
|
48
|
+
context.report({
|
|
49
|
+
messageId: "sort",
|
|
50
|
+
loc: {
|
|
51
|
+
start: sourceCode.getLocFromIndex(start),
|
|
52
|
+
end: sourceCode.getLocFromIndex(end)
|
|
53
|
+
},
|
|
54
|
+
fix: (fixer) => fixer.replaceTextRange([start, end], sorted)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function printSortedItems(sortedItems, originalItems, sourceCode) {
|
|
59
|
+
const newline = guessNewline(sourceCode);
|
|
60
|
+
const sorted = sortedItems.map(
|
|
61
|
+
(groups) => groups.map((groupItems) => groupItems.map((item) => item.code).join(newline)).join(newline)
|
|
62
|
+
).join(newline + newline);
|
|
63
|
+
const flattened = flatMap(sortedItems, (groups) => [].concat(...groups));
|
|
64
|
+
const lastSortedItem = flattened[flattened.length - 1];
|
|
65
|
+
const lastOriginalItem = originalItems[originalItems.length - 1];
|
|
66
|
+
const nextToken = lastSortedItem.needsNewline ? sourceCode.getTokenAfter(lastOriginalItem.node, {
|
|
67
|
+
includeComments: true,
|
|
68
|
+
filter: (token) => !isLineComment(token) && !(isBlockComment(token) && token.loc.end.line === lastOriginalItem.node.loc.end.line)
|
|
69
|
+
}) : void 0;
|
|
70
|
+
const maybeNewline = nextToken != null && nextToken.loc.start.line === lastOriginalItem.node.loc.end.line ? newline : "";
|
|
71
|
+
return sorted + maybeNewline;
|
|
72
|
+
}
|
|
73
|
+
function getImportExportItems(passedChunk, sourceCode, isSideEffectImport, getSpecifiers) {
|
|
74
|
+
const chunk = handleLastSemicolon(passedChunk, sourceCode);
|
|
75
|
+
return chunk.map((node, nodeIndex) => {
|
|
76
|
+
const lastLine = nodeIndex === 0 ? node.loc.start.line - 1 : chunk[nodeIndex - 1].loc.end.line;
|
|
77
|
+
const commentsBefore = sourceCode.getCommentsBefore(node).filter(
|
|
78
|
+
(comment) => comment.loc.start.line <= node.loc.start.line && comment.loc.end.line > lastLine && (nodeIndex > 0 || comment.loc.start.line > lastLine)
|
|
79
|
+
);
|
|
80
|
+
const commentsAfter = sourceCode.getCommentsAfter(node).filter((comment) => comment.loc.end.line === node.loc.end.line);
|
|
81
|
+
const before = printCommentsBefore(node, commentsBefore, sourceCode);
|
|
82
|
+
const after = printCommentsAfter(node, commentsAfter, sourceCode);
|
|
83
|
+
const indentation = getIndentation(
|
|
84
|
+
commentsBefore.length > 0 ? commentsBefore[0] : node,
|
|
85
|
+
sourceCode
|
|
86
|
+
);
|
|
87
|
+
const trailingSpaces = getTrailingSpaces(
|
|
88
|
+
commentsAfter.length > 0 ? commentsAfter[commentsAfter.length - 1] : node,
|
|
89
|
+
sourceCode
|
|
90
|
+
);
|
|
91
|
+
const code = indentation + before + printWithSortedSpecifiers(node, sourceCode, getSpecifiers) + after + trailingSpaces;
|
|
92
|
+
const all = [...commentsBefore, node, ...commentsAfter];
|
|
93
|
+
const [start] = all[0].range;
|
|
94
|
+
const [, end] = all[all.length - 1].range;
|
|
95
|
+
const source = getSource(node);
|
|
96
|
+
return {
|
|
97
|
+
node,
|
|
98
|
+
code,
|
|
99
|
+
start: start - indentation.length,
|
|
100
|
+
end: end + trailingSpaces.length,
|
|
101
|
+
isSideEffectImport: isSideEffectImport(node, sourceCode),
|
|
102
|
+
source,
|
|
103
|
+
index: nodeIndex,
|
|
104
|
+
needsNewline: commentsAfter.length > 0 && isLineComment(commentsAfter[commentsAfter.length - 1])
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function handleLastSemicolon(chunk, sourceCode) {
|
|
109
|
+
const lastIndex = chunk.length - 1;
|
|
110
|
+
const lastNode = chunk[lastIndex];
|
|
111
|
+
const [nextToLastToken, lastToken] = sourceCode.getLastTokens(lastNode, {
|
|
112
|
+
count: 2
|
|
113
|
+
});
|
|
114
|
+
const lastIsSemicolon = isPunctuator(lastToken, ";");
|
|
115
|
+
if (!lastIsSemicolon) {
|
|
116
|
+
return chunk;
|
|
117
|
+
}
|
|
118
|
+
const semicolonBelongsToNode = nextToLastToken.loc.end.line === lastToken.loc.start.line || // If there’s no more code after the last import/export the semicolon has to
|
|
119
|
+
// belong to the import/export, even if it is not on the same line.
|
|
120
|
+
sourceCode.getTokenAfter(lastToken) == null;
|
|
121
|
+
if (semicolonBelongsToNode) {
|
|
122
|
+
return chunk;
|
|
123
|
+
}
|
|
124
|
+
const newLastNode = {
|
|
125
|
+
...lastNode,
|
|
126
|
+
range: [lastNode.range[0], nextToLastToken.range[1]],
|
|
127
|
+
loc: {
|
|
128
|
+
start: lastNode.loc.start,
|
|
129
|
+
end: nextToLastToken.loc.end
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return chunk.slice(0, lastIndex).concat(newLastNode);
|
|
133
|
+
}
|
|
134
|
+
function printWithSortedSpecifiers(node, sourceCode, getSpecifiers) {
|
|
135
|
+
const allTokens = getAllTokens(node, sourceCode);
|
|
136
|
+
const openBraceIndex = allTokens.findIndex(
|
|
137
|
+
(token) => isPunctuator(token, "{")
|
|
138
|
+
);
|
|
139
|
+
const closeBraceIndex = allTokens.findIndex(
|
|
140
|
+
(token) => isPunctuator(token, "}")
|
|
141
|
+
);
|
|
142
|
+
const specifiers = getSpecifiers(node);
|
|
143
|
+
if (openBraceIndex === -1 || closeBraceIndex === -1 || specifiers.length <= 1) {
|
|
144
|
+
return printTokens(allTokens);
|
|
145
|
+
}
|
|
146
|
+
const specifierTokens = allTokens.slice(openBraceIndex + 1, closeBraceIndex);
|
|
147
|
+
const itemsResult = getSpecifierItems(specifierTokens, sourceCode);
|
|
148
|
+
const items = itemsResult.items.map((originalItem, index) => ({
|
|
149
|
+
...originalItem,
|
|
150
|
+
node: specifiers[index]
|
|
151
|
+
}));
|
|
152
|
+
const sortedItems = sortSpecifierItems(items);
|
|
153
|
+
const newline = guessNewline(sourceCode);
|
|
154
|
+
const hasTrailingComma = isPunctuator(
|
|
155
|
+
sourceCode.getTokenBefore(allTokens[closeBraceIndex]),
|
|
156
|
+
","
|
|
157
|
+
);
|
|
158
|
+
const lastIndex = sortedItems.length - 1;
|
|
159
|
+
const sorted = flatMap(sortedItems, (item, index) => {
|
|
160
|
+
const previous = index === 0 ? void 0 : sortedItems[index - 1];
|
|
161
|
+
const maybeNewline2 = previous != null && needsStartingNewline(item.before) && !(previous.after.length > 0 && isNewline(previous.after[previous.after.length - 1])) ? [{ type: "Newline", code: newline }] : [];
|
|
162
|
+
if (index < lastIndex || hasTrailingComma) {
|
|
163
|
+
return [
|
|
164
|
+
...maybeNewline2,
|
|
165
|
+
...item.before,
|
|
166
|
+
...item.specifier,
|
|
167
|
+
{ type: "Comma", code: "," },
|
|
168
|
+
...item.after
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
const nonBlankIndex = item.after.findIndex(
|
|
172
|
+
(token) => !isNewline(token) && !isSpaces(token)
|
|
173
|
+
);
|
|
174
|
+
const after = !item.hadComma ? item.after : nonBlankIndex === -1 ? [] : item.after.slice(nonBlankIndex);
|
|
175
|
+
return [...maybeNewline2, ...item.before, ...item.specifier, ...after];
|
|
176
|
+
});
|
|
177
|
+
const maybeNewline = needsStartingNewline(itemsResult.after) && !isNewline(sorted[sorted.length - 1]) ? [{ type: "Newline", code: newline }] : [];
|
|
178
|
+
return printTokens([
|
|
179
|
+
...allTokens.slice(0, openBraceIndex + 1),
|
|
180
|
+
...itemsResult.before,
|
|
181
|
+
...sorted,
|
|
182
|
+
...maybeNewline,
|
|
183
|
+
...itemsResult.after,
|
|
184
|
+
...allTokens.slice(closeBraceIndex)
|
|
185
|
+
]);
|
|
186
|
+
}
|
|
187
|
+
function getSpecifierItems(tokens) {
|
|
188
|
+
const result = {
|
|
189
|
+
before: [],
|
|
190
|
+
after: [],
|
|
191
|
+
items: []
|
|
192
|
+
};
|
|
193
|
+
let current = makeEmptyItem();
|
|
194
|
+
for (const token of tokens) {
|
|
195
|
+
switch (current.state) {
|
|
196
|
+
case "before":
|
|
197
|
+
switch (token.type) {
|
|
198
|
+
case "Newline":
|
|
199
|
+
current.before.push(token);
|
|
200
|
+
if (result.before.length === 0 && result.items.length === 0) {
|
|
201
|
+
result.before = current.before;
|
|
202
|
+
current = makeEmptyItem();
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case "Spaces":
|
|
206
|
+
case "Block":
|
|
207
|
+
case "Line":
|
|
208
|
+
current.before.push(token);
|
|
209
|
+
break;
|
|
210
|
+
// We’ve reached an identifier.
|
|
211
|
+
default:
|
|
212
|
+
if (result.before.length === 0 && result.items.length === 0) {
|
|
213
|
+
result.before = current.before;
|
|
214
|
+
current = makeEmptyItem();
|
|
215
|
+
}
|
|
216
|
+
current.state = "specifier";
|
|
217
|
+
current.specifier.push(token);
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
case "specifier":
|
|
221
|
+
switch (token.type) {
|
|
222
|
+
case "Punctuator":
|
|
223
|
+
if (isPunctuator(token, ",")) {
|
|
224
|
+
current.hadComma = true;
|
|
225
|
+
current.state = "after";
|
|
226
|
+
} else {
|
|
227
|
+
current.specifier.push(token);
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
// When consuming the specifier part, we eat every token until a comma
|
|
231
|
+
// or to the end, basically.
|
|
232
|
+
default:
|
|
233
|
+
current.specifier.push(token);
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
case "after":
|
|
237
|
+
switch (token.type) {
|
|
238
|
+
// Only whitespace and comments after a specifier that are on the same
|
|
239
|
+
// belong to the specifier.
|
|
240
|
+
case "Newline":
|
|
241
|
+
current.after.push(token);
|
|
242
|
+
result.items.push(current);
|
|
243
|
+
current = makeEmptyItem();
|
|
244
|
+
break;
|
|
245
|
+
case "Spaces":
|
|
246
|
+
case "Line":
|
|
247
|
+
current.after.push(token);
|
|
248
|
+
break;
|
|
249
|
+
case "Block":
|
|
250
|
+
if (hasNewline(token.code)) {
|
|
251
|
+
result.items.push(current);
|
|
252
|
+
current = makeEmptyItem();
|
|
253
|
+
current.before.push(token);
|
|
254
|
+
} else {
|
|
255
|
+
current.after.push(token);
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
// We’ve reached another specifier – time to process that one.
|
|
259
|
+
default:
|
|
260
|
+
result.items.push(current);
|
|
261
|
+
current = makeEmptyItem();
|
|
262
|
+
current.state = "specifier";
|
|
263
|
+
current.specifier.push(token);
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
/* v8 ignore start */
|
|
267
|
+
default:
|
|
268
|
+
throw new Error(`Unknown state: ${current.state}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
switch (current.state) {
|
|
272
|
+
// If the last specifier has a trailing comma and some of the remaining
|
|
273
|
+
// whitespace and comments are on the same line we end up here. If so we
|
|
274
|
+
// want to put that whitespace and comments in `result.after`.
|
|
275
|
+
case "before":
|
|
276
|
+
result.after = current.before;
|
|
277
|
+
break;
|
|
278
|
+
// If the last specifier has no trailing comma we end up here. Move all
|
|
279
|
+
// trailing comments and whitespace from `.specifier` to `.after`, and
|
|
280
|
+
// comments and whitespace that don’t belong to the specifier to
|
|
281
|
+
// `result.after`. The last non-comment and non-whitespace token is usually
|
|
282
|
+
// an identifier, but in this case it’s a keyword:
|
|
283
|
+
//
|
|
284
|
+
// export { z, d as default } from "a"
|
|
285
|
+
case "specifier": {
|
|
286
|
+
const lastIdentifierIndex = findLastIndex(
|
|
287
|
+
current.specifier,
|
|
288
|
+
(token2) => isIdentifier(token2) || isKeyword(token2)
|
|
289
|
+
);
|
|
290
|
+
const specifier = current.specifier.slice(0, lastIdentifierIndex + 1);
|
|
291
|
+
const after = current.specifier.slice(lastIdentifierIndex + 1);
|
|
292
|
+
const newlineIndexRaw = after.findIndex((token2) => isNewline(token2));
|
|
293
|
+
const newlineIndex = newlineIndexRaw === -1 ? -1 : newlineIndexRaw + 1;
|
|
294
|
+
const multilineBlockCommentIndex = after.findIndex(
|
|
295
|
+
(token2) => isBlockComment(token2) && hasNewline(token2.code)
|
|
296
|
+
);
|
|
297
|
+
const sliceIndex = (
|
|
298
|
+
// If both a newline and a multiline block comment exists, choose the
|
|
299
|
+
// earlier one.
|
|
300
|
+
newlineIndex >= 0 && multilineBlockCommentIndex >= 0 ? Math.min(newlineIndex, multilineBlockCommentIndex) : newlineIndex >= 0 ? newlineIndex : multilineBlockCommentIndex >= 0 ? multilineBlockCommentIndex : (
|
|
301
|
+
// If there are no newlines, move the last whitespace into `result.after`.
|
|
302
|
+
endsWithSpaces(after) ? after.length - 1 : -1
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
current.specifier = specifier;
|
|
306
|
+
current.after = sliceIndex === -1 ? after : after.slice(0, sliceIndex);
|
|
307
|
+
result.items.push(current);
|
|
308
|
+
result.after = sliceIndex === -1 ? [] : after.slice(sliceIndex);
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
// If the last specifier has a trailing comma and all remaining whitespace
|
|
312
|
+
// and comments are on the same line we end up here. If so we want to move
|
|
313
|
+
// the final whitespace to `result.after`.
|
|
314
|
+
case "after":
|
|
315
|
+
if (endsWithSpaces(current.after)) {
|
|
316
|
+
const last = current.after.pop();
|
|
317
|
+
result.after = [last];
|
|
318
|
+
}
|
|
319
|
+
result.items.push(current);
|
|
320
|
+
break;
|
|
321
|
+
/* v8 ignore start */
|
|
322
|
+
default:
|
|
323
|
+
throw new Error(`Unknown state: ${current.state}`);
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
function makeEmptyItem() {
|
|
328
|
+
return {
|
|
329
|
+
// "before" | "specifier" | "after"
|
|
330
|
+
state: "before",
|
|
331
|
+
before: [],
|
|
332
|
+
after: [],
|
|
333
|
+
specifier: [],
|
|
334
|
+
hadComma: false
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function needsStartingNewline(tokens) {
|
|
338
|
+
const before = tokens.filter((token) => !isSpaces(token));
|
|
339
|
+
if (before.length === 0) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
const firstToken = before[0];
|
|
343
|
+
return isLineComment(firstToken) || isBlockComment(firstToken) && !hasNewline(firstToken.code);
|
|
344
|
+
}
|
|
345
|
+
function endsWithSpaces(tokens) {
|
|
346
|
+
const last = tokens.length > 0 ? tokens[tokens.length - 1] : void 0;
|
|
347
|
+
return last == null ? false : isSpaces(last);
|
|
348
|
+
}
|
|
349
|
+
var NEWLINE = /(\r?\n)/;
|
|
350
|
+
function hasNewline(string) {
|
|
351
|
+
return NEWLINE.test(string);
|
|
352
|
+
}
|
|
353
|
+
function guessNewline(sourceCode) {
|
|
354
|
+
const match = NEWLINE.exec(sourceCode.text);
|
|
355
|
+
return match == null ? "\n" : match[0];
|
|
356
|
+
}
|
|
357
|
+
function parseWhitespace(whitespace) {
|
|
358
|
+
const allItems = whitespace.split(NEWLINE);
|
|
359
|
+
const items = allItems.length >= 5 ? allItems.slice(0, 2).concat(allItems.slice(-1)) : allItems;
|
|
360
|
+
return items.map(
|
|
361
|
+
(spacesOrNewline, index) => index % 2 === 0 ? { type: "Spaces", code: spacesOrNewline } : { type: "Newline", code: spacesOrNewline }
|
|
362
|
+
).filter((token) => token.code !== "");
|
|
363
|
+
}
|
|
364
|
+
function removeBlankLines(whitespace) {
|
|
365
|
+
return printTokens(parseWhitespace(whitespace));
|
|
366
|
+
}
|
|
367
|
+
function getAllTokens(node, sourceCode) {
|
|
368
|
+
const tokens = sourceCode.getTokens(node);
|
|
369
|
+
const lastTokenIndex = tokens.length - 1;
|
|
370
|
+
return flatMap(tokens, (token, tokenIndex) => {
|
|
371
|
+
const newToken = { ...token, code: sourceCode.getText(token) };
|
|
372
|
+
if (tokenIndex === lastTokenIndex) {
|
|
373
|
+
return [newToken];
|
|
374
|
+
}
|
|
375
|
+
const comments = sourceCode.getCommentsAfter(token);
|
|
376
|
+
const last = comments.length > 0 ? comments[comments.length - 1] : token;
|
|
377
|
+
const nextToken = tokens[tokenIndex + 1];
|
|
378
|
+
return [
|
|
379
|
+
newToken,
|
|
380
|
+
...flatMap(comments, (comment, commentIndex) => {
|
|
381
|
+
const previous = commentIndex === 0 ? token : comments[commentIndex - 1];
|
|
382
|
+
return [
|
|
383
|
+
...parseWhitespace(
|
|
384
|
+
sourceCode.text.slice(previous.range[1], comment.range[0])
|
|
385
|
+
),
|
|
386
|
+
{ ...comment, code: sourceCode.getText(comment) }
|
|
387
|
+
];
|
|
388
|
+
}),
|
|
389
|
+
...parseWhitespace(
|
|
390
|
+
sourceCode.text.slice(last.range[1], nextToken.range[0])
|
|
391
|
+
)
|
|
392
|
+
];
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function printTokens(tokens) {
|
|
396
|
+
return tokens.map((token) => token.code).join("");
|
|
397
|
+
}
|
|
398
|
+
function printCommentsBefore(node, comments, sourceCode) {
|
|
399
|
+
const lastIndex = comments.length - 1;
|
|
400
|
+
return comments.map((comment, index) => {
|
|
401
|
+
const next = index === lastIndex ? node : comments[index + 1];
|
|
402
|
+
return sourceCode.getText(comment) + removeBlankLines(sourceCode.text.slice(comment.range[1], next.range[0]));
|
|
403
|
+
}).join("");
|
|
404
|
+
}
|
|
405
|
+
function printCommentsAfter(node, comments, sourceCode) {
|
|
406
|
+
return comments.map((comment, index) => {
|
|
407
|
+
const previous = index === 0 ? node : comments[index - 1];
|
|
408
|
+
return removeBlankLines(
|
|
409
|
+
sourceCode.text.slice(previous.range[1], comment.range[0])
|
|
410
|
+
) + sourceCode.getText(comment);
|
|
411
|
+
}).join("");
|
|
412
|
+
}
|
|
413
|
+
function getIndentation(node, sourceCode) {
|
|
414
|
+
const tokenBefore = sourceCode.getTokenBefore(node, {
|
|
415
|
+
includeComments: true
|
|
416
|
+
});
|
|
417
|
+
if (tokenBefore == null) {
|
|
418
|
+
const text2 = sourceCode.text.slice(0, node.range[0]);
|
|
419
|
+
const lines2 = text2.split(NEWLINE);
|
|
420
|
+
return lines2[lines2.length - 1];
|
|
421
|
+
}
|
|
422
|
+
const text = sourceCode.text.slice(tokenBefore.range[1], node.range[0]);
|
|
423
|
+
const lines = text.split(NEWLINE);
|
|
424
|
+
return lines.length > 1 ? lines[lines.length - 1] : "";
|
|
425
|
+
}
|
|
426
|
+
function getTrailingSpaces(node, sourceCode) {
|
|
427
|
+
const tokenAfter = sourceCode.getTokenAfter(node, {
|
|
428
|
+
includeComments: true
|
|
429
|
+
});
|
|
430
|
+
if (tokenAfter == null) {
|
|
431
|
+
const text2 = sourceCode.text.slice(node.range[1]);
|
|
432
|
+
const lines2 = text2.split(NEWLINE);
|
|
433
|
+
return lines2[0];
|
|
434
|
+
}
|
|
435
|
+
const text = sourceCode.text.slice(node.range[1], tokenAfter.range[0]);
|
|
436
|
+
const lines = text.split(NEWLINE);
|
|
437
|
+
return lines[0];
|
|
438
|
+
}
|
|
439
|
+
function sortImportExportItems(items) {
|
|
440
|
+
return items.slice().sort(
|
|
441
|
+
(itemA, itemB) => (
|
|
442
|
+
// If both items are side effect imports, keep their original order.
|
|
443
|
+
itemA.isSideEffectImport && itemB.isSideEffectImport ? itemA.index - itemB.index : (
|
|
444
|
+
// If one of the items is a side effect import, move it first.
|
|
445
|
+
itemA.isSideEffectImport ? -1 : itemB.isSideEffectImport ? 1 : (
|
|
446
|
+
// Compare the `from` part.
|
|
447
|
+
compare(itemA.source.source, itemB.source.source) || // The `.source` has been slightly tweaked. To stay fully deterministic,
|
|
448
|
+
// also sort on the original value.
|
|
449
|
+
compare(itemA.source.originalSource, itemB.source.originalSource) || // Then put type imports/exports before regular ones.
|
|
450
|
+
compare(itemA.source.kind, itemB.source.kind) || // Keep the original order if the sources are the same. It’s not worth
|
|
451
|
+
// trying to compare anything else, and you can use `import/no-duplicates`
|
|
452
|
+
// to get rid of the problem anyway.
|
|
453
|
+
itemA.index - itemB.index
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
function sortSpecifierItems(items) {
|
|
460
|
+
return items.slice().sort(
|
|
461
|
+
(itemA, itemB) => (
|
|
462
|
+
// Compare by imported or exported name (external interface name).
|
|
463
|
+
// import { a as b } from "a"
|
|
464
|
+
// ^
|
|
465
|
+
// export { b as a }
|
|
466
|
+
// ^
|
|
467
|
+
compare(
|
|
468
|
+
(itemA.node.imported || itemA.node.exported).name,
|
|
469
|
+
(itemB.node.imported || itemB.node.exported).name
|
|
470
|
+
) || // Then compare by the file-local name.
|
|
471
|
+
// import { a as b } from "a"
|
|
472
|
+
// ^
|
|
473
|
+
// export { b as a }
|
|
474
|
+
// ^
|
|
475
|
+
compare(itemA.node.local.name, itemB.node.local.name) || // Then put type specifiers before regular ones.
|
|
476
|
+
compare(
|
|
477
|
+
getImportExportKind(itemA.node),
|
|
478
|
+
getImportExportKind(itemB.node)
|
|
479
|
+
/* v8 ignore start */
|
|
480
|
+
) || // Keep the original order if the names are the same. It’s not worth
|
|
481
|
+
// trying to compare anything else, `import {a, a} from "mod"` is a syntax
|
|
482
|
+
// error anyway (but @babel/eslint-parser kind of supports it).
|
|
483
|
+
itemA.index - itemB.index
|
|
484
|
+
)
|
|
485
|
+
/* v8 ignore stop */
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
var collator = new Intl.Collator("en", {
|
|
489
|
+
sensitivity: "base",
|
|
490
|
+
numeric: true
|
|
491
|
+
});
|
|
492
|
+
function compare(a, b) {
|
|
493
|
+
return collator.compare(a, b) || (a < b ? -1 : a > b ? 1 : 0);
|
|
494
|
+
}
|
|
495
|
+
function isIdentifier(node) {
|
|
496
|
+
return node.type === "Identifier";
|
|
497
|
+
}
|
|
498
|
+
function isKeyword(node) {
|
|
499
|
+
return node.type === "Keyword";
|
|
500
|
+
}
|
|
501
|
+
function isPunctuator(node, value) {
|
|
502
|
+
return node.type === "Punctuator" && node.value === value;
|
|
503
|
+
}
|
|
504
|
+
function isBlockComment(node) {
|
|
505
|
+
return node.type === "Block";
|
|
506
|
+
}
|
|
507
|
+
function isLineComment(node) {
|
|
508
|
+
return node.type === "Line";
|
|
509
|
+
}
|
|
510
|
+
function isSpaces(node) {
|
|
511
|
+
return node.type === "Spaces";
|
|
512
|
+
}
|
|
513
|
+
function isNewline(node) {
|
|
514
|
+
return node.type === "Newline";
|
|
515
|
+
}
|
|
516
|
+
function getSource(node) {
|
|
517
|
+
const source = node.source.value;
|
|
518
|
+
return {
|
|
519
|
+
// Sort by directory level rather than by string length.
|
|
520
|
+
source: source.replace(/^[./]*\.$/, "$&/").replace(/^[./]*\/$/, "$&,").replace(/[./_-]/g, (char) => {
|
|
521
|
+
switch (char) {
|
|
522
|
+
case ".":
|
|
523
|
+
return "_";
|
|
524
|
+
case "/":
|
|
525
|
+
return "-";
|
|
526
|
+
case "_":
|
|
527
|
+
return ".";
|
|
528
|
+
case "-":
|
|
529
|
+
return "/";
|
|
530
|
+
/* v8 ignore start */
|
|
531
|
+
default:
|
|
532
|
+
throw new Error(`Unknown source substitution character: ${char}`);
|
|
533
|
+
}
|
|
534
|
+
}),
|
|
535
|
+
originalSource: source,
|
|
536
|
+
kind: getImportExportKind(node)
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
function getImportExportKind(node) {
|
|
540
|
+
return node.importKind || node.exportKind || "value";
|
|
541
|
+
}
|
|
542
|
+
function findLastIndex(array, fn) {
|
|
543
|
+
for (let index = array.length - 1; index >= 0; index--) {
|
|
544
|
+
if (fn(array[index], index, array)) {
|
|
545
|
+
return index;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return -1;
|
|
549
|
+
}
|
|
550
|
+
function flatMap(array, fn) {
|
|
551
|
+
return [].concat(...array.map(fn));
|
|
552
|
+
}
|
|
553
|
+
function getSourceCode(context) {
|
|
554
|
+
return context.sourceCode || context.getSourceCode();
|
|
555
|
+
}
|
|
556
|
+
module.exports = {
|
|
557
|
+
extractChunks,
|
|
558
|
+
flatMap,
|
|
559
|
+
getImportExportItems,
|
|
560
|
+
getSourceCode,
|
|
561
|
+
isPunctuator,
|
|
562
|
+
maybeReportSorting,
|
|
563
|
+
printSortedItems,
|
|
564
|
+
printWithSortedSpecifiers,
|
|
565
|
+
sortImportExportItems
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
// node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/imports.js
|
|
571
|
+
var require_imports = __commonJS({
|
|
572
|
+
"node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/imports.js"(exports, module) {
|
|
573
|
+
"use strict";
|
|
574
|
+
init_esm_shims();
|
|
575
|
+
var shared = require_shared();
|
|
576
|
+
var defaultGroups = [
|
|
577
|
+
// Side effect imports.
|
|
578
|
+
["^\\u0000"],
|
|
579
|
+
// Node.js builtins prefixed with `node:`.
|
|
580
|
+
["^node:"],
|
|
581
|
+
// Packages.
|
|
582
|
+
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
|
|
583
|
+
["^@?\\w"],
|
|
584
|
+
// Absolute imports and other imports such as Vue-style `@/foo`.
|
|
585
|
+
// Anything not matched in another group.
|
|
586
|
+
["^"],
|
|
587
|
+
// Relative imports.
|
|
588
|
+
// Anything that starts with a dot.
|
|
589
|
+
["^\\."]
|
|
590
|
+
];
|
|
591
|
+
module.exports = {
|
|
592
|
+
meta: {
|
|
593
|
+
type: "layout",
|
|
594
|
+
fixable: "code",
|
|
595
|
+
schema: [
|
|
596
|
+
{
|
|
597
|
+
type: "object",
|
|
598
|
+
properties: {
|
|
599
|
+
groups: {
|
|
600
|
+
type: "array",
|
|
601
|
+
items: {
|
|
602
|
+
type: "array",
|
|
603
|
+
items: {
|
|
604
|
+
type: "string"
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
additionalProperties: false
|
|
610
|
+
}
|
|
611
|
+
],
|
|
612
|
+
docs: {
|
|
613
|
+
url: "https://github.com/lydell/eslint-plugin-simple-import-sort#sort-order",
|
|
614
|
+
description: "Automatically sort imports."
|
|
615
|
+
},
|
|
616
|
+
messages: {
|
|
617
|
+
sort: "Run autofix to sort these imports!"
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
create: (context) => {
|
|
621
|
+
const { groups: rawGroups = defaultGroups } = context.options[0] || {};
|
|
622
|
+
const outerGroups = rawGroups.map(
|
|
623
|
+
(groups) => groups.map((item) => RegExp(item, "u"))
|
|
624
|
+
);
|
|
625
|
+
const parents = /* @__PURE__ */ new Set();
|
|
626
|
+
return {
|
|
627
|
+
ImportDeclaration: (node) => {
|
|
628
|
+
parents.add(node.parent);
|
|
629
|
+
},
|
|
630
|
+
"Program:exit": () => {
|
|
631
|
+
for (const parent of parents) {
|
|
632
|
+
for (const chunk of shared.extractChunks(
|
|
633
|
+
parent,
|
|
634
|
+
(node) => isImport(node) ? "PartOfChunk" : "NotPartOfChunk"
|
|
635
|
+
)) {
|
|
636
|
+
maybeReportChunkSorting(chunk, context, outerGroups);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
parents.clear();
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
function maybeReportChunkSorting(chunk, context, outerGroups) {
|
|
645
|
+
const sourceCode = shared.getSourceCode(context);
|
|
646
|
+
const items = shared.getImportExportItems(
|
|
647
|
+
chunk,
|
|
648
|
+
sourceCode,
|
|
649
|
+
isSideEffectImport,
|
|
650
|
+
getSpecifiers
|
|
651
|
+
);
|
|
652
|
+
const sortedItems = makeSortedItems(items, outerGroups);
|
|
653
|
+
const sorted = shared.printSortedItems(sortedItems, items, sourceCode);
|
|
654
|
+
const { start } = items[0];
|
|
655
|
+
const { end } = items[items.length - 1];
|
|
656
|
+
shared.maybeReportSorting(context, sorted, start, end);
|
|
657
|
+
}
|
|
658
|
+
function makeSortedItems(items, outerGroups) {
|
|
659
|
+
const itemGroups = outerGroups.map(
|
|
660
|
+
(groups) => groups.map((regex) => ({ regex, items: [] }))
|
|
661
|
+
);
|
|
662
|
+
const rest = [];
|
|
663
|
+
for (const item of items) {
|
|
664
|
+
const { originalSource } = item.source;
|
|
665
|
+
const source = item.isSideEffectImport ? `\0${originalSource}` : item.source.kind !== "value" ? `${originalSource}\0` : originalSource;
|
|
666
|
+
const [matchedGroup] = shared.flatMap(
|
|
667
|
+
itemGroups,
|
|
668
|
+
(groups) => groups.map((group) => [group, group.regex.exec(source)])
|
|
669
|
+
).reduce(
|
|
670
|
+
([group, longestMatch], [nextGroup, nextMatch]) => nextMatch != null && (longestMatch == null || nextMatch[0].length > longestMatch[0].length) ? [nextGroup, nextMatch] : [group, longestMatch],
|
|
671
|
+
[void 0, void 0]
|
|
672
|
+
);
|
|
673
|
+
if (matchedGroup == null) {
|
|
674
|
+
rest.push(item);
|
|
675
|
+
} else {
|
|
676
|
+
matchedGroup.items.push(item);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return itemGroups.concat([[{ regex: /^/, items: rest }]]).map((groups) => groups.filter((group) => group.items.length > 0)).filter((groups) => groups.length > 0).map(
|
|
680
|
+
(groups) => groups.map((group) => shared.sortImportExportItems(group.items))
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
function getSpecifiers(importNode) {
|
|
684
|
+
return importNode.specifiers.filter((node) => isImportSpecifier(node));
|
|
685
|
+
}
|
|
686
|
+
function isImport(node) {
|
|
687
|
+
return node.type === "ImportDeclaration";
|
|
688
|
+
}
|
|
689
|
+
function isImportSpecifier(node) {
|
|
690
|
+
return node.type === "ImportSpecifier";
|
|
691
|
+
}
|
|
692
|
+
function isSideEffectImport(importNode, sourceCode) {
|
|
693
|
+
return importNode.specifiers.length === 0 && (!importNode.importKind || importNode.importKind === "value") && !shared.isPunctuator(sourceCode.getFirstToken(importNode, { skip: 1 }), "{");
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
// node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/exports.js
|
|
699
|
+
var require_exports = __commonJS({
|
|
700
|
+
"node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/exports.js"(exports, module) {
|
|
701
|
+
"use strict";
|
|
702
|
+
init_esm_shims();
|
|
703
|
+
var shared = require_shared();
|
|
704
|
+
module.exports = {
|
|
705
|
+
meta: {
|
|
706
|
+
type: "layout",
|
|
707
|
+
fixable: "code",
|
|
708
|
+
schema: [],
|
|
709
|
+
docs: {
|
|
710
|
+
url: "https://github.com/lydell/eslint-plugin-simple-import-sort#sort-order",
|
|
711
|
+
description: "Automatically sort exports."
|
|
712
|
+
},
|
|
713
|
+
messages: {
|
|
714
|
+
sort: "Run autofix to sort these exports!"
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
create: (context) => {
|
|
718
|
+
const parents = /* @__PURE__ */ new Set();
|
|
719
|
+
const addParent = (node) => {
|
|
720
|
+
if (isExportFrom(node)) {
|
|
721
|
+
parents.add(node.parent);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
return {
|
|
725
|
+
ExportNamedDeclaration: (node) => {
|
|
726
|
+
if (node.source == null && node.declaration == null) {
|
|
727
|
+
maybeReportExportSpecifierSorting(node, context);
|
|
728
|
+
} else {
|
|
729
|
+
addParent(node);
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
ExportAllDeclaration: addParent,
|
|
733
|
+
"Program:exit": () => {
|
|
734
|
+
const sourceCode = shared.getSourceCode(context);
|
|
735
|
+
for (const parent of parents) {
|
|
736
|
+
for (const chunk of shared.extractChunks(
|
|
737
|
+
parent,
|
|
738
|
+
(node, lastNode) => isPartOfChunk(node, lastNode, sourceCode)
|
|
739
|
+
)) {
|
|
740
|
+
maybeReportChunkSorting(chunk, context);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
parents.clear();
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
function maybeReportChunkSorting(chunk, context) {
|
|
749
|
+
const sourceCode = shared.getSourceCode(context);
|
|
750
|
+
const items = shared.getImportExportItems(
|
|
751
|
+
chunk,
|
|
752
|
+
sourceCode,
|
|
753
|
+
() => false,
|
|
754
|
+
// isSideEffectImport
|
|
755
|
+
getSpecifiers
|
|
756
|
+
);
|
|
757
|
+
const sortedItems = [[shared.sortImportExportItems(items)]];
|
|
758
|
+
const sorted = shared.printSortedItems(sortedItems, items, sourceCode);
|
|
759
|
+
const { start } = items[0];
|
|
760
|
+
const { end } = items[items.length - 1];
|
|
761
|
+
shared.maybeReportSorting(context, sorted, start, end);
|
|
762
|
+
}
|
|
763
|
+
function maybeReportExportSpecifierSorting(node, context) {
|
|
764
|
+
const sorted = shared.printWithSortedSpecifiers(
|
|
765
|
+
node,
|
|
766
|
+
shared.getSourceCode(context),
|
|
767
|
+
getSpecifiers
|
|
768
|
+
);
|
|
769
|
+
const [start, end] = node.range;
|
|
770
|
+
shared.maybeReportSorting(context, sorted, start, end);
|
|
771
|
+
}
|
|
772
|
+
function getSpecifiers(exportNode) {
|
|
773
|
+
return exportNode.specifiers || [];
|
|
774
|
+
}
|
|
775
|
+
function isPartOfChunk(node, lastNode, sourceCode) {
|
|
776
|
+
if (!isExportFrom(node)) {
|
|
777
|
+
return "NotPartOfChunk";
|
|
778
|
+
}
|
|
779
|
+
const hasGroupingComment = sourceCode.getCommentsBefore(node).some(
|
|
780
|
+
(comment) => (lastNode == null || comment.loc.start.line > lastNode.loc.end.line) && comment.loc.end.line < node.loc.start.line
|
|
781
|
+
);
|
|
782
|
+
return hasGroupingComment ? "PartOfNewChunk" : "PartOfChunk";
|
|
783
|
+
}
|
|
784
|
+
function isExportFrom(node) {
|
|
785
|
+
return (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") && node.source != null;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
// node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/index.js
|
|
791
|
+
var require_eslint_plugin_simple_import_sort = __commonJS({
|
|
792
|
+
"node_modules/.pnpm/eslint-plugin-simple-import-sort@12.1.1_eslint@9.25.1_jiti@2.4.2_/node_modules/eslint-plugin-simple-import-sort/index.js"(exports, module) {
|
|
793
|
+
init_esm_shims();
|
|
794
|
+
var importsRule = require_imports();
|
|
795
|
+
var exportsRule = require_exports();
|
|
796
|
+
module.exports = {
|
|
797
|
+
meta: {
|
|
798
|
+
name: "eslint-plugin-simple-import-sort",
|
|
799
|
+
version: "12.1.1"
|
|
800
|
+
},
|
|
801
|
+
rules: {
|
|
802
|
+
imports: importsRule,
|
|
803
|
+
exports: exportsRule
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
export default require_eslint_plugin_simple_import_sort();
|