Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-beautiful-sort

allohamora153MIT3.0.1TypeScript support: included

eslint plugin for imports sort by their type

eslint, plugin, sort, import, imports-sort, sort-imports

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.1 (2023-04-09)

Features

  • add disable sorting example to README.md (33dba8e)
  • add more badges to README.md (5508ed2)

3.0.0 (2023-04-09)

Features

2.0.4 (2022-12-01)

Bug Fixes

2.0.3 (2022-03-04)

Bug Fixes

2.0.2 (2022-03-02)

Bug Fixes

2.0.1 (2022-02-04)

Features

  • add normal examples to README (7eff771)

Bug Fixes

  • fix wrong spaces in README (db5aaab)

2.0.0 (2022-02-03)

⚠ BREAKING CHANGES

  • rewrite to typescript

Features

Bug Fixes

  • fix at is not a function (f168b46)

1.0.7 (2022-02-02)

Bug Fixes

  • invalid defaultObj parsing (c51b194)