Finds your tsconfig.json
and uses that to separate imports.
- Absolute imports without members.
- Node modules.
- Absolute imports with members.
- Typescript path imports with members.
- Typescript path imports without members.
- Relative imports with members.
- Relative imports without members.
Example:
import 'ignore-styles';
import path from 'path';
import React from 'react';
import MyComponent from 'src/components/my';
import 'src/theme/style.css';
import Box from './box';
import './style.css';
npm install --save-dev \
forked-import-sort \
forked-import-sort-cli \
forked-import-sort-parser-typescript \
import-sort-style-module-tsconfig
Add following to your package.json
:
"lint-staged": {
"*.{tsx,ts}": [
/* ... */
"import-sort --write .",
"git add"
]
},
"importSort": {
".ts, .tsx": {
"parser": "forked-import-sort-parser-typescript",
"style": "module-tsconfig",
"options": {}
}
}
Either install sort-imports for VSCode, or use via CLI (file watcher, etc.):
npx import-sort --write .
You may also pass options to this style by putting them to options
directive in package.json
.
Key | Type | Default | Description |
---|---|---|---|
isolatePaths | boolean | true | Separates every tsconfig path as new group |
workingDir | string | unset | Used as directory for tsconfig.json resolution |