organizeDirectives function
Takes in a file as a string and organizes the imports and exports. Sorts imports/exports and removes double quotes.
Throws an ArgumentError if sourceFileContents
cannot be parsed.
Implementation
String organizeDirectives(String sourceFileContents) {
final directives = parseString(content: sourceFileContents)
.unit
.accept(NamespaceCollector())!;
if (directives.isEmpty) {
return sourceFileContents;
}
final namespaces = _assignCommentsInFileToNamespaceDirective(
sourceFileContents,
directives,
);
final sortedDirectives = _organizeDirectives(sourceFileContents, namespaces);
return _replaceDirectives(sourceFileContents, namespaces, sortedDirectives);
}