eslint-plugin-beautiful-sort
eslint plugin for imports sort 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';
import * as utils from 'src/utils';
import Link from '../Link';
import ApiService, { Options } from './api.service';
import { compose, pipe, curry } from 'src/utils/fp';
import './styles.css';
Plugin tested on
{
"node": "^16.13.2",
"npm": "^8.1.2",
"eslint": "^8.8.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';
import * as utils from 'src/utils';
import Link from '../Link';
import ApiService, { Options } from './api.service';
import { compose, pipe, curry } from 'src/utils/fp';
import './styles.css';