VSCode has an editor feature, which allows to clean and order imports in javascript and typescript files on saving ( "source.organizeImports": true
).
Question
How can I call this action on a file from the command line ?
something like :
tslint --fix [apply ordered-imports rule] file1 file2
but it seems tslint has its own implementation for "ordered-imports"
What I gathered so far
From what I understood, this feature triggers a call to the organizeImports
function in typescript's codebase.
This functionnality is part of typescript's Language Service, but I don't know how to start a language service daemon, and how to interact with it.
Since the code is written in that function, there also probably is a way to call it synchronously from a ts script, but I couldn't find an example of how to setup the objects and variables from scratch to feed them to this function.
The organize-imports-cli
package does what you want:
https://www.npmjs.com/package/organize-imports-cli
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With