
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
prettier-plugin-sorted
Advanced tools
Sort your JavaScript and TypeScript imports with prettier with automatic alias support
An elegant prettier plugin for sorting your imports. It automatically checks you typescript tsconfig configuration and sorts aliases by default.
prettier-plugin-sorted
is a prettier
plugin for automatically sorting all you JavaScript and TypeScript imports. It uses import-sort
and allows for a zero configuration setup which should be sufficient for most setups.
Sort the modules in the following order.
import 'tolu';
import { join } from 'path';
import main from 'main';
tsconfig.json
and extraAliases
setting, but excluding ignoredAliases
.bottomAliases
. These group together absolute paths with relative, placing the absolute paths above the relative.An example is shown below.
// Imports with no members are left unsorted since they may have side effects.
import 'dotenv';
import './my-side-effect';
import 'firebase/auth';
// Built in node module imports come next
import { join } from 'path';
// Absolute imports
import Awesome from 'awesome-package';
import { B, C } from 'bcde';
// Aliased imports
import MyAlias from '@my-alias';
import { Simple } from 'simple';
// Relative imports
import { DeepRelative } from '../../deep/relative';
import Relative from './relative';
// Bottom imports
import Bottom from '@bottom';
import { relativeBottom } from './relative/bottom';
First, install the plugin and the required parser:
npm install --save-dev prettier-plugin-sorted prettier
Or if you're using Yarn.
yarn add -D prettier-plugin-sorted prettier
Add the plugin to your prettier
configuration.
.prettierrc.json
{
"plugins": ["prettier-plugin-sorted"]
}
Or inside your project's package.json
file.
{
"prettier": {
"plugins": ["prettier-plugin-sorted"]
}
}
If you would like to customise the setup you can add the importSort
field to you package.json
file. A better explanation on what each configuration option does is available here.
"importSort": {
".js, jsx, .ts, .tsx": {
"options": {
"cacheStrategy": "directory",
"wildcardAtStart": false,
"extraAliases": [],
"ignoredAliases": [],
"bottomAliases": []
}
}
}
The following animated flow shows what it's like when this is setup with prettier in your editor.
This project uses SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details
Ifiok Jr. 💻 | Guy Gascoigne-Piggford 💻 |
prettier-plugin-import-sort
with a sharper focus on typescript projects.FAQs
Sort your JavaScript and TypeScript imports with prettier with automatic alias support
The npm package prettier-plugin-sorted receives a total of 1,031 weekly downloads. As such, prettier-plugin-sorted popularity was classified as popular.
We found that prettier-plugin-sorted demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.