Skip to content

Commit

Permalink
Fix notebook lint for namespace imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 1, 2024
1 parent 6187ab4 commit 96efe70
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/core_docs/scripts/validate_notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function extract(filepath: string) {
const importDeclarations = sourceFile.getImportDeclarations();
const uniqueImports = new Map<
string,
{ default?: string; named: Set<string> }
{ default?: string; namespace?: string; named: Set<string> }
>();

importDeclarations.forEach((importDecl) => {
Expand All @@ -29,6 +29,10 @@ export function extract(filepath: string) {
if (defaultImport) {
uniqueImports.get(moduleSpecifier)!.default = defaultImport.getText();
}
const namespaceImport = importDecl.getNamespaceImport();
if (namespaceImport) {
uniqueImports.get(moduleSpecifier)!.namespace = namespaceImport.getText();
}
importDecl.getNamedImports().forEach((namedImport) => {
uniqueImports.get(moduleSpecifier)!.named.add(namedImport.getText());
});
Expand All @@ -39,10 +43,11 @@ export function extract(filepath: string) {

// Add deduplicated imports at the top
uniqueImports.forEach(
({ default: defaultImport, named }, moduleSpecifier) => {
({ default: defaultImport, namespace, named }, moduleSpecifier) => {
sourceFile.addImportDeclaration({
moduleSpecifier,
defaultImport,
namespaceImport: namespace,
namedImports: Array.from(named),
});
}
Expand Down

0 comments on commit 96efe70

Please sign in to comment.