@so1ve/eslint-plugin-sort-imports 1.4.0 → 1.5.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/package.json +4 -4
- package/src/exports.js +1 -1
- package/src/imports.js +3 -3
- package/src/shared.js +24 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@so1ve/eslint-plugin-sort-imports",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": "Simon Lydell",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Ray <i@mk1.io> (https://github.com/so1ve)"
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"sorter",
|
|
18
18
|
"sorting"
|
|
19
19
|
],
|
|
20
|
-
"homepage": "https://github.com/so1ve/
|
|
20
|
+
"homepage": "https://github.com/so1ve/codestyle-config#readme",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/so1ve/
|
|
23
|
+
"url": "git+https://github.com/so1ve/codestyle-config.git"
|
|
24
24
|
},
|
|
25
25
|
"bugs": {
|
|
26
|
-
"url": "https://github.com/so1ve/
|
|
26
|
+
"url": "https://github.com/so1ve/codestyle-config/issues"
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"main": "src/index.js",
|
package/src/exports.js
CHANGED
|
@@ -88,7 +88,7 @@ module.exports = {
|
|
|
88
88
|
"ExportAllDeclaration": addParent,
|
|
89
89
|
|
|
90
90
|
"Program:exit": () => {
|
|
91
|
-
const sourceCode = context.
|
|
91
|
+
const sourceCode = context.sourceCode;
|
|
92
92
|
for (const parent of parents) {
|
|
93
93
|
for (const chunk of shared.extractChunks(parent, (node, lastNode) =>
|
|
94
94
|
isPartOfChunk(node, lastNode, sourceCode),
|
package/src/imports.js
CHANGED
|
@@ -94,7 +94,7 @@ module.exports = {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
function maybeReportChunkSorting(chunk, context, outerGroups) {
|
|
97
|
-
const sourceCode = context.
|
|
97
|
+
const sourceCode = context.sourceCode;
|
|
98
98
|
const items = shared.getImportExportItems(
|
|
99
99
|
chunk,
|
|
100
100
|
sourceCode,
|
|
@@ -119,8 +119,8 @@ function makeSortedItems(items, outerGroups) {
|
|
|
119
119
|
const source = item.isSideEffectImport
|
|
120
120
|
? `\0${originalSource}`
|
|
121
121
|
: item.source.kind === "value"
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
? originalSource
|
|
123
|
+
: `${originalSource}\0`;
|
|
124
124
|
const [matchedGroup] = shared
|
|
125
125
|
// eslint-disable-next-line unicorn/no-array-method-this-argument
|
|
126
126
|
.flatMap(itemGroups, (groups) =>
|
package/src/shared.js
CHANGED
|
@@ -250,21 +250,21 @@ const sortImportExportItems = (items) =>
|
|
|
250
250
|
itemA.isSideEffectImport && itemB.isSideEffectImport
|
|
251
251
|
? itemA.index - itemB.index
|
|
252
252
|
: // If one of the items is a side effect import, move it first.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
253
|
+
itemA.isSideEffectImport
|
|
254
|
+
? -1
|
|
255
|
+
: itemB.isSideEffectImport
|
|
256
|
+
? 1
|
|
257
|
+
: // Compare the `from` part.
|
|
258
|
+
compare(itemA.source.source, itemB.source.source) ||
|
|
259
|
+
// The `.source` has been slightly tweaked. To stay fully deterministic,
|
|
260
|
+
// also sort on the original value.
|
|
261
|
+
compare(itemA.source.originalSource, itemB.source.originalSource) ||
|
|
262
|
+
// Then put type imports/exports before regular ones.
|
|
263
|
+
compare(itemA.source.kind, itemB.source.kind) ||
|
|
264
|
+
// Keep the original order if the sources are the same. It’s not worth
|
|
265
|
+
// trying to compare anything else, and you can use `import/no-duplicates`
|
|
266
|
+
// to get rid of the problem anyway.
|
|
267
|
+
itemA.index - itemB.index,
|
|
268
268
|
);
|
|
269
269
|
|
|
270
270
|
const sortSpecifierItems = (items) =>
|
|
@@ -345,7 +345,7 @@ function extractChunks(parentNode, isPartOfChunk) {
|
|
|
345
345
|
}
|
|
346
346
|
|
|
347
347
|
function maybeReportSorting(context, sorted, start, end) {
|
|
348
|
-
const sourceCode = context.
|
|
348
|
+
const sourceCode = context.sourceCode;
|
|
349
349
|
const original = sourceCode.getText().slice(start, end);
|
|
350
350
|
if (original !== sorted) {
|
|
351
351
|
context.report({
|
|
@@ -385,7 +385,7 @@ function printSortedItems(sortedItems, originalItems, sourceCode) {
|
|
|
385
385
|
isBlockComment(token) &&
|
|
386
386
|
token.loc.end.line === lastOriginalItem.node.loc.end.line
|
|
387
387
|
),
|
|
388
|
-
|
|
388
|
+
})
|
|
389
389
|
: undefined;
|
|
390
390
|
const maybeNewline =
|
|
391
391
|
nextToken != null &&
|
|
@@ -814,13 +814,13 @@ function getSpecifierItems(tokens) {
|
|
|
814
814
|
newlineIndex >= 0 && multilineBlockCommentIndex >= 0
|
|
815
815
|
? Math.min(newlineIndex, multilineBlockCommentIndex)
|
|
816
816
|
: newlineIndex >= 0
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
817
|
+
? newlineIndex
|
|
818
|
+
: multilineBlockCommentIndex >= 0
|
|
819
|
+
? multilineBlockCommentIndex
|
|
820
|
+
: // If there are no newlines, move the last whitespace into `result.after`.
|
|
821
|
+
endsWithSpaces(after)
|
|
822
|
+
? after.length - 1
|
|
823
|
+
: -1;
|
|
824
824
|
|
|
825
825
|
current.specifier = specifier;
|
|
826
826
|
current.after = sliceIndex === -1 ? after : after.slice(0, sliceIndex);
|