eslint-plugin-beautiful-sort
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

eslint-plugin-beautiful-sort

npm build test release

eslint plugin to sort imports by their type

Example

From:

import './styles.css';
import { compose, pipe, curry } from 'src/utils/fp';
import ApiService, { Options } from './api.service';
import Link from '../Link';
import * as utils from 'src/utils';
import React from 'react';

To:

import React from 'react'; // special
import * as utils from 'src/utils'; // namespace
import Link from '../Link'; // default
import ApiService, { Options } from './api.service'; // defaultObj
import { compose, pipe, curry } from 'src/utils/fp'; // obj
import './styles.css'; // none

Disable sorting:

/* eslint-disable beautiful-sort/import */
import './styles.css';
import { compose, pipe, curry } from 'src/utils/fp';
import ApiService, { Options } from './api.service';
import Link from '../Link';
import * as utils from 'src/utils';
import React from 'react';

Plugin tested on

{
  "node": "^18.14.0",
  "npm": "^9.3.1",
  "eslint": "^8.38.0"
}

Usage

npm i -D eslint-plugin-beautiful-sort
{
  "plugins": ["beautiful-sort"],
  "rules": {
    "beautiful-sort/import": [
      "error",
      {
        "special": ["react"],
        "order": ["special", "namespace", "default", "defaultObj", "obj", "none"]
      }
    ]
  }
}

API

Special

special is an array of module paths or a string regexp such as "/^src/utils/string$/"

Order

order is an array of import types;

Import type

import type is a string that specifies one of the following imports:

import React from 'react'; // special
import * as utils from 'src/utils'; // namespace
import Link from '../Link'; // default
import ApiService, { Options } from './api.service'; // defaultObj
import { compose, pipe, curry } from 'src/utils/fp'; // obj
import './styles.css'; // none

Dependents (1)

Package Sidebar

Install

npm i eslint-plugin-beautiful-sort

Weekly Downloads

57

Version

3.0.1

License

MIT

Unpacked Size

56.5 kB

Total Files

22

Last publish

Collaborators

  • allohamora