npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-imports-perfectionist-order

v1.1.1

Published

ESLint plugin that allows you to efficiently sort imports and is fully configurable according to your preferences.

Readme

eslint-plugin-imports-perfectionist-order

| main / latest | develop | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | npm version (latest) | npm version (develop) | | Build Status (latest) | Build Status (develop) |

License: MIT

ESLint plugin to sort imports with fully configurable strategies. Allows you to define custom sorting rules for your project's imports.

Features

  • Multiple sorting strategies: Sort by line length, path depth, filename or alphabetically
  • Grouping support: Separate external and internal imports
  • Flexible configuration: Combine strategies in any order
  • Auto-fix: Automatically fixes import order issues
  • TypeScript support: Works seamlessly with TypeScript and modern JavaScript projects

Requirements

  • Node.js: >= 18.0.0
  • ESLint: >= 8.0.0
  • Yarn: >= 4.10.3 (recommended) or npm >= 9.0.0

Compatibility Note: See COMPATIBILITY.md for details on compatibility with different Node.js and ESLint versions.

Table of content

Installation

# Using npm
npm install --save-dev eslint-plugin-imports-perfectionist-order

# Using Yarn (recommended)
yarn add -D eslint-plugin-imports-perfectionist-order

# Using pnpm
pnpm add -D eslint-plugin-imports-perfectionist-order

Quick Start

Default configuration

Flat (ESLint 9+)

// eslint.config.js
export default [
	{
		plugins: { 'imports-perfectionist-order': import('eslint-plugin-imports-perfectionist-order') },
		rules: { 'imports-perfectionist-order/sort': ['error'] },
	},
];

Legacy (ESLint < 9)

// .eslintrc.js
module.exports = {
	plugins: ['imports-perfectionist-order'],
	rules: { 'imports-perfectionist-order/sort': ['error'] },
};

Custom configuration

Flat (ESLint 9+)

// eslint.config.js
export default [
	{
		plugins: { 'imports-perfectionist-order': import('eslint-plugin-imports-perfectionist-order') },
		rules: {
			'imports-perfectionist-order/sort': [
				'error',
				{
					groups: true,
					internalPattern: '^(@/|\\.\\.?/)',
					sortStrategies: ['pathTree', 'alphabetical'],
				},
			],
		},
	},
];

Legacy (ESLint < 9)

// .eslintrc.js
module.exports = {
	plugins: ['imports-perfectionist-order'],
	rules: {
		'imports-perfectionist-order/sort': [
			'error',
			{
				groups: true,
				internalPattern: '^(@/|\\.\\.?/)',
				sortStrategies: ['pathTree', 'alphabetical'],
			},
		],
	},
};

Configuration options

groups (boolean, default: true)

Defines whether external and internal imports should be grouped separately. When enabled, external imports appear first, followed by internal imports.

Accepted values:

  • true: Enables grouping (default)
  • false: Disables grouping

Example:

// groups: true
import express from 'express';
import lodash from 'lodash';
import config from '../config'; // Internal (starts with '../')
import utils from './utils'; // Internal (starts with './')

// groups: false
import config from '../config';
import express from 'express';
import lodash from 'lodash';
import utils from './utils';

internalPattern (string, default : ^(@/|\\.\\.?/))

Regular expression pattern to identify internal imports. By default, matches:

  • ^@/ : import aliases (as used in projects with path aliases)
  • ^\.\.?/ : relative imports (./ or ../)

Example:

// To also consider paths starting with 'src/' as internal
{
  internalPattern: '^(src/|@/|\\.\\.?/)',
  groups: true
}

sortStrategies (array of strategies, default : [PATH_TREE_DEPTH, FILENAME, ALPHABETICAL, LINE_LENGTH])

Which strategies should be applied one after another over the result of the previous applied strategies.

Example:

// Simple ASC by default strategies
{
  sortStrategies: ['pathTree', 'alphabetical']
}

// Advanced strategies direction
{
	sortStrategies: [
		{ strategy: SortStrategy.PATH_TREE_DEPTH, direction: SortDirection.ASC },
		{ strategy: SortStrategy.FILENAME, direction: SortDirection.ASC },
		{ strategy: SortStrategy.ALPHABETICAL, direction: SortDirection.ASC },
		{ strategy: SortStrategy.LINE_LENGTH, direction: SortDirection.ASC },
	],
}

Strategies

The plugin offers several sorting strategies that you can combine according to your needs.

1. lineLength

Sorts imports by line length (from shortest to longest).

Benefits :

  • Improves readability with short imports at the top
  • Reduces Git merge conflicts

Example :

// Before
import { veryLongNamedUtility } from './utils/very-long-path/very-long-named-utility';
import { config } from './config';
import { api } from './api';

// After
import { api } from './api';
import { config } from './config';
import { veryLongNamedUtility } from './utils/very-long-path/very-long-named-utility';
2. pathTree

Sorts by path depth (from deepest to shallowest).

Example :

// Before
import { utils } from '../../utils';
import { api } from '../../../api';
import { config } from './config';

// After
import { api } from '../../../api';
import { utils } from '../../utils';
import { config } from './config';
3. alphabetical

Sorts imports alphabetically.

Example :

// Before
import { z } from 'z';
import { a } from 'a';
import { m } from 'm';

// After
import { a } from 'a';
import { m } from 'm';
import { z } from 'z';
4. filename

Sorts imports by filename (last part of the path).

Example :

// Before
import { utils } from './utils';
import { config } from './config';
import { api } from '../api';

// After
import { api } from '../api';
import { config } from './config';
import { utils } from './utils';

Examples

Example 1: Sort by line length, then alphabetically (with grouping)

// Configuration
{
  "groups": true,
  "sortStrategies": ["lineLength", "alphabetical"]
}

// Before
import lodash from 'lodash';
import express from 'express';
import fs from 'fs';
import utils from './utils';

// After
import fs from 'fs';
import lodash from 'lodash';
import express from 'express';

import utils from './utils';

Example 2: Sort by path tree depth, then alphabetically (no grouping)

// Configuration
{
  "groups": false,
  "sortStrategies": ["pathTreeDepth", "alphabetical"]
}

// Before
import utils from './utils';
import config from '../config';
import helper from '../../helper';

// After
import helper from '../../helper';
import config from '../config';
import utils from './utils';

Example 3: Alphabetical sort with grouping

// Configuration
{
  "groups": true,
  "sortStrategies": ["alphabetical"]
}

// Before
import utils from './utils';
import express from 'express';
import fs from 'fs';

// After
import express from 'express';
import fs from 'fs';

import utils from './utils';

Development

See CONTRIBUTING.md for tutorial and guidelines.

Reporting Issues

Before reporting an issue, please check if it hasn't been already reported in the GitHub issues.

How to Report a Bug

  1. Use the provided bug report template
  2. Include a clear, descriptive title
  3. Describe the expected and actual behavior
  4. Provide steps to reproduce the issue
  5. Include relevant code snippets

Required Information

  • Plugin version
  • ESLint version
  • Node.js version
  • ESLint configuration used
  • Affected files (if applicable)
  • Complete error messages

Questions?

If you have questions or need help getting started, feel free to:

  1. Check the documentation
  2. Browse existing issues
  3. Open an issue if your question hasn't been asked

Acknowledgments

Thank you for contributing to this project! Your time and effort are greatly appreciated.

License

MIT License