Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
import-sort-style-custom
Advanced tools
Sort your imports using import-sort with aliases and custom configurations
Sort your imports taking into account your aliased tsconfig paths and other custom options. These paths are treated as internal imports.
import-sort-style-custom
is designed to be used with import-sort
and provide a customisable way for ordering imports when aliases are also used for internal imports.
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 available 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 import-sort-style-custom import-sort-parser-typescript
or
yarn add -D import-sort-style-custom import-sort-parser-typescript
Add the following to your package.json
file.
"importSort": {
".js, .ts, .tsx": {
"parser": "typescript",
"style": "custom",
"options": {
"cacheStrategy": "directory",
"wildcardAtStart": false,
"extraAliases": [],
"ignoredAliases": [],
"bottomAliases": []
}
}
}
Property | Type | Default | Description |
---|---|---|---|
ignoreTsConfig | boolean | false | When true will not search for any tsconfig.json. This might provide a slight performance boost. This options takes precedence over the other tsconfig options. |
tsconfigName | string | 'tsconfig.json' | The name to use when searching for a TsConfig. |
tsconfigFilePath | string | undefined | A direct path to the tsconfig file relative to the cwd . |
cacheStrategy | 'directory' or 'never' or 'always' | 'directory' | Determines how often to check for a new parent tsconfig file. By default it will check every time the directory changes. If you only have one tsconfig.json file for the whole project with consistent it makes sense to update this to 'never'. |
wildcardAtStart | boolean | false | When true will allow patterns which start with a * character. |
extraAliases | string[] | [] | Extra patterns that should be recognised as internal aliases. The pattern is the same as tsconfig files support supporting * as the wildcard character. |
ignoredAliases | string[] | [] | Ignore all paths that match this pattern. This takes preference over any matching aliases. If a module path matches the alias but doesn't The pattern is the same as tsconfig files support supporting * as the wildcard character. |
bottomAliases | string[] | [] | Files matching this pattern will be moved to a special group at the end of the imports. The pattern is the same as tsconfig files support supporting * as the wildcard character. |
Install the prettier plugin.
npm install --save-dev prettier prettier-plugin-import-sort
or
yarn add -D prettier prettier-plugin-import-sort
Add the plugin to your prettier
configuration.
.prettierrc
{
"plugins": ["prettier-plugin-import-sort"]
}
Then add the following configuration to your package.json
, with any options you'd also like to add.
"importSort": {
".js, .ts, .tsx": {
"parser": "typescript",
"style": "custom",
"options": {}
}
}
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
FAQs
Sort your imports using import-sort with aliases and custom configurations
We found that import-sort-style-custom 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.