Package Exports
- @mattinton/prettier-plugin-tidy-imports
- @mattinton/prettier-plugin-tidy-imports/dist/main.js
- @mattinton/prettier-plugin-tidy-imports/dist/module.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mattinton/prettier-plugin-tidy-imports) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Prettier Plugin Tidy Imports
A prettier plugin that, sorts, combines, and removes unsused imports from your Javascript/Typescript project.
Example
Before
After
Sorting
After removing any unused imports, imports are sorted into 4 distinct groups Side Efffect
, Namespace
, Third Party
, and Relative
. Every group is then sorted alphabetically except Side Effect
imports where their ordering matters. Inside Third Party
and Relative
import groups, default
imports are placed at the top, and named imports (imports inside {}
) are also ordered.
Example definitions
- Side Effect -
tailwindcss/tailwind.css
- Namespace -
import * as yup from "yup"
- Third Party -
import { merge } from "lodash"
- Relative -
import Utils, { map, filter } from './utils
NOTE: This package doesn't know the difference between
Third Party
imports, and aliases defined in thetsconfig.json
paths config. If you want to make sure these are group separately, you should prefix your aliases with a symbol not used in third party modules such as the tilde (~
).
Installation
npm install --save-dev @mattinton/prettier-plugin-tidy-imports
yarn add -D @mattinton/prettier-plugin-tidy-imports
NOTE: This package requires
prettier
andtypescript
to be installed as peer dependencies.
Usage Warning
This plugin breaks Prettier's rule of only printing code as plugin actually transforms your imports. If this concerns you please don't use this package.