Skip to content

Commit

Permalink
Make the analyze-field-access command exit with 1 on error
Browse files Browse the repository at this point in the history
Refs: #20
  • Loading branch information
nene committed Jan 19, 2024
1 parent 70dae0e commit c643fed
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions scripts/analyze-field-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const options = {
target: ts.ScriptTarget.ES2015,
module: ts.ModuleKind.CommonJS,
};
// We'll be populating this when we detect unused fields
const errors: string[] = [];

let program = ts.createProgram(fileNames, options);
let checker = program.getTypeChecker();
Expand All @@ -22,6 +24,12 @@ for (const sourceFile of program.getSourceFiles()) {
}
}

if (errors.length > 0) {
console.log(`Found ${errors.length} problems:\n`);
console.error(errors.join("\n\n"));
process.exit(1);
}

function isSyntaxMapFile(fileName: string): boolean {
return (
fileName.includes("src/syntax/") && !fileName.endsWith("transformMap.ts")
Expand Down Expand Up @@ -74,12 +82,13 @@ function analyzeObjectProperty(node: ts.Node, sourceFile: ts.SourceFile) {
.map(([key]) => key);

if (missingFields.length > 0) {
console.log(``);
console.log(`Unused fields: ${missingFields.join(", ")}`);
console.log(
`In file: ${sourceFile.fileName.replace(/.*\//, "src/syntax/")}`,
errors.push(
[
`In file: ${sourceFile.fileName.replace(/.*\//, "src/syntax/")}`,
`Unused fields: ${missingFields.join(", ")}`,
node.getText(sourceFile),
].join("\n"),
);
console.log(node.getText(sourceFile));
}
}

Expand Down

0 comments on commit c643fed

Please sign in to comment.