Skip to content

Commit

Permalink
fix: fix race condition when fixing multiple members in the same file
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-zhong committed Jul 1, 2021
1 parent 78f66e7 commit b3bd1cc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/fix.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as t from "ts-morph";
import { IOffendingMembers } from "./analyze";
import { SourceFile } from "ts-morph";

export const fix = (membersToFix: IOffendingMembers[]): Promise<unknown> => {
const savePromises: Promise<void>[] = [];
const touchedFiles: Set<SourceFile> = new Set();

membersToFix.forEach(({ file, declaration, reason }) => {
if (reason === "unused") {
declaration.remove();
Expand All @@ -11,8 +13,8 @@ export const fix = (membersToFix: IOffendingMembers[]): Promise<unknown> => {
declaration.set({ scope: t.Scope.Private });
}

savePromises.push(file.save());
touchedFiles.add(file);
});

return Promise.all(savePromises);
return Promise.all(Array.from(touchedFiles).map((file) => file.save()));
};

0 comments on commit b3bd1cc

Please sign in to comment.