-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: π re-runing the conductor adds an extra new line
β Closes: #37
- Loading branch information
1 parent
6a41aba
commit ff8bc6d
Showing
5 changed files
with
27 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
import { ImportCategories } from '../types'; | ||
|
||
const categoriesOrder = ['thirdPartyImports', 'userLibraryImports', 'differentModuleImports', 'sameModuleImports']; | ||
|
||
export function formatImportStatements(importCategories: ImportCategories) { | ||
const { differentModuleImports, sameModuleImports, thirdPartyImports, userLibraryImports } = importCategories; | ||
let result = ''; | ||
const [first, ...otherCategories] = Object.entries(importCategories) | ||
.filter(([, imports]) => imports.size > 0) | ||
.sort(([a], [b]) => categoriesOrder.indexOf(a) - categoriesOrder.indexOf(b)) | ||
.map(([, imports]) => imports); | ||
|
||
function updateResult(sortedPot: Map<string, string>, spaceBefore = true) { | ||
if (sortedPot.size > 0 && spaceBefore) { | ||
result += '\n\n'; | ||
} | ||
[...sortedPot.values()].forEach( | ||
(fullImportLiteral: string, index: number) => | ||
(result += index === sortedPot.size - 1 ? `${fullImportLiteral}` : `${fullImportLiteral}\n`) | ||
); | ||
} | ||
let result = first ? [...first.values()].join('\n') : ''; | ||
|
||
updateResult(thirdPartyImports, false); | ||
updateResult(userLibraryImports, thirdPartyImports.size > 0); | ||
updateResult(differentModuleImports, thirdPartyImports.size > 0 || userLibraryImports.size > 0); | ||
updateResult(sameModuleImports, thirdPartyImports.size > 0 || userLibraryImports.size > 0 || differentModuleImports.size > 0); | ||
for (const imports of otherCategories) { | ||
result += '\n\n' + [...imports.values()].join('\n'); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters