@leanix/import-sort-style
v1.0.6
Published
Custom LeanIX style for JS/TS import-sort package
Downloads
345
Readme
@leanix/import-sort-style
This import-sort is based on import-sort-style-module.
Installation
- Install with
npm i -D @leanix/import-sort-style
- If used with Prettier, install
npm i -D [email protected]
for Prettier@v1 andnpm i -D prettier-plugin-import-sort
for Prettier@v2
Configuration
- Add a configuration like the following to your package.json to specify the parser (which may need to be installed separately) and the corresponding extensions:
"importSort": {
".js, .ts": {
"style": "@leanix/import-sort-style",
"parser": "typescript",
"options": {
"prefixes": [
"@app",
"@lib"
]
}
}
}
- The list of local prefixes/aliases is optional.
Sort order
The order of imports is:
- Third-party modules with side effects are not sorted because order may matter, e.g.
import 'polyfills';
- Local, absolute modules with side-effects are not sorted because order may matter, e.g.
import '@app/polyfills';
- Local, relative modules with side effects are not sorted because order may matter, e.g.
import './polyfills';
- Third-party modules are sorted by name, e.g.
import { endOfMonth } from 'date-fns';
- Built-in Node.js modules are sorted by name, e.g.
import * as fs from 'fs';
- Local, absolute modules are sorted by the prefix-order provided and then by name
import { LIMIT } from '@app/app.constants';
- Local, relative modules are sorted by "relative depth" and then by name
import { LIMIT } from './app.constants';
See the tests for more examples.