Skip to content

Commit

Permalink
format and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 15, 2024
1 parent bf4466e commit 646869a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libs/langchain-scripts/src/validate_notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import ts from "typescript";
import { Project } from "ts-morph";

export function extract(filepath: string) {
const cells = JSON.parse(fs.readFileSync(filepath).toString()).cells;
const { cells } = JSON.parse(fs.readFileSync(filepath).toString());
if (cells[0]?.source.includes("lc_docs_skip_validation: true\n")) {
return "";
}
const project = new Project({ useInMemoryFileSystem: true });
const sourceFile = project.createSourceFile("temp.ts", "");

// eslint-disable-next-line @typescript-eslint/no-explicit-any
cells.forEach((cell: Record<string, any>) => {
const source = cell.source
.join("")
Expand Down Expand Up @@ -62,7 +63,7 @@ export function extract(filepath: string) {
return sourceFile.getFullText();
}

let [pathname] = process.argv.slice(2);
const [pathname] = process.argv.slice(2);

if (!pathname) {
throw new Error("No pathname provided.");
Expand All @@ -73,6 +74,7 @@ const run = async () => {
pathname,
processCwd: process.cwd(),
});

if (!pathname.endsWith(".ipynb")) {
throw new Error("Only .ipynb files are supported.");
}
Expand Down Expand Up @@ -122,6 +124,7 @@ const run = async () => {
const issues = issueStrings.join("\n");
console.error(issues);
const err = new Error("Found type errors in new notebook.");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(err as any).details = issues;
throw err;
}
Expand All @@ -135,7 +138,7 @@ const run = async () => {
};

try {
run();
void run();
} catch {
process.exit(1);
}

0 comments on commit 646869a

Please sign in to comment.