@leanix/import-sort-style
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

@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 prettier-plugin-import-sort@0.0.3 for Prettier@v1 and npm 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:

  1. Third-party modules with side effects are not sorted because order may matter, e.g. import 'polyfills';
  2. Local, absolute modules with side-effects are not sorted because order may matter, e.g. import '@app/polyfills';
  3. Local, relative modules with side effects are not sorted because order may matter, e.g. import './polyfills';
  4. Third-party modules are sorted by name, e.g. import { endOfMonth } from 'date-fns';
  5. Built-in Node.js modules are sorted by name, e.g. import * as fs from 'fs';
  6. Local, absolute modules are sorted by the prefix-order provided and then by name import { LIMIT } from '@app/app.constants';
  7. Local, relative modules are sorted by "relative depth" and then by name import { LIMIT } from './app.constants';

See the tests for more examples.

Readme

Keywords

Package Sidebar

Install

npm i @leanix/import-sort-style

Weekly Downloads

121

Version

1.0.6

License

none

Unpacked Size

5.75 kB

Total Files

4

Last publish

Collaborators

  • leanix