prettier-plugin-fix-imports
v0.0.1
Published
Make prettier organize your imports using the TypeScript language service API.
Downloads
34
Maintainers
Readme
Prettier Plugin: Organize Imports
Make sure that your import statements stay consistent no matter who writes them and what their preferences are.
A plugin that makes Prettier organize your imports (i. e. sort and remove unused imports) using the organizeImports
feature of the TypeScript language service API. This is the same as using the "Organize Imports" action in VS Code.
Installation
npm install --save-dev prettier-plugin-organize-imports
prettier
and typescript
are peer dependencies, so make sure you have those installed in your project.
Usage
The plugin will be loaded by Prettier automatically. No configuration needed.
Files containing the substring // organize-imports-ignore
or // tslint:disable:ordered-imports
are skipped.
Rationale
This plugin acts outside of Prettier's scope because "Prettier only prints code. It does not transform it.", and technically sorting is a code transformation because it changes the AST (this plugin even removes code, i. e. unused imports). In my opinion however, the import statements are not really part of the code, they are merely directives that instruct the module system where to find the code (only true as long as your imports are side-effects free regarding the global scope, i. e. import order doesn't matter), comparable with using
directives in C# or #include
preprocessing directives in C. Therefore the practical benefits outweigh sticking with the philosophy in this case.
License
MIT.