Need help with prettier-plugin-organize-imports?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

simonhaenisch
196 Stars 7 Forks MIT License 36 Commits 1 Opened issues

Description

Make Prettier organize your imports using the TypeScript language service API.

Services available

!
?

Need anything else?

Contributors list

# 11,515
TypeScr...
ionic
ionic-f...
Firebas...
32 commits
# 48,987
ESLint
lodash
React
CSS
2 commits
# 2,062
Visual ...
Markdow...
Angular
printer
1 commit

Tests

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.