UNPKG

monk-import-export

Version:

Simple import & export sorting ESLint plugin

28 lines (27 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortImportExportItems = void 0; const compare_1 = require("./compare"); function sortImportExportItems(items) { return items.slice().sort((itemA, itemB) => // If both items are side effect imports, keep their original order. itemA.isSideEffectImport && itemB.isSideEffectImport ? itemA.index - itemB.index : // If one of the items is a side effect import, move it first. itemA.isSideEffectImport ? -1 : itemB.isSideEffectImport ? 1 : // Compare the `from` part. (0, compare_1.compare)(itemA.source.source, itemB.source.source) || // The `.source` has been slightly tweaked. To stay fully deterministic, // also sort on the original value. (0, compare_1.compare)(itemA.source.originalSource, itemB.source.originalSource) || // Then put type imports/exports before regular ones. (0, compare_1.compare)(itemA.source.kind, itemB.source.kind) || // Keep the original order if the sources are the same. It’s not worth // trying to compare anything else, and you can use `import/no-duplicates` // to get rid of the problem anyway. itemA.index - itemB.index); } exports.sortImportExportItems = sortImportExportItems;