In vscode, there is option to remove unused imports, add all missing imports, and prettify (ALT + SHIFT +f).
I have files generator, and i wont to do all this stuff via code
In vscode, there is option to remove unused imports, add all missing imports, and prettify (ALT + SHIFT +f).
I have files generator, and i wont to do all this stuff via code
This is possible with my library ts-morph. Here's some sample code that does this for every file associated with a tsconfig.json:
import { Project } from "ts-morph";
const project = new Project({ tsConfigFilePath: "tsconfig.json" });
for (const sourceFile of project.getSourceFiles()) {
sourceFile.fixMissingImports()
.organizeImports()
.fixUnusedIdentifiers()
.formatText();
}
project.save().then(() => console.log("done"));
All of these methods accept arguments for specifying how formatting should be done (limited by the configurations available in the compiler API).