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-import-length-sort

v1.1.2

Published

Sorts imports by line length (default-ish first, then named-only), longest to shortest.

Readme

eslint-plugin-import-length-sort

ESLint plugin that sorts imports by line length (default-ish first, then named-only), longest to shortest.

Demo

Installation

npm install --save-dev eslint-plugin-import-length-sort

or with yarn:

yarn add --dev eslint-plugin-import-length-sort

Usage

Flat Config (ESLint 9+)

import importLengthSort from "eslint-plugin-import-length-sort";

export default [
  {
    files: ["**/*.{js,jsx,ts,tsx,mjs,cjs}"],
    plugins: {
      "import-length-sort": importLengthSort,
    },
    rules: {
      "import-length-sort/sort": "warn",
    },
  },
];

Legacy Config (.eslintrc)

{
  "plugins": ["import-length-sort"],
  "rules": {
    "import-length-sort/sort": "warn"
  },
  "overrides": [
    {
      "files": ["*.js", "*.jsx", "*.ts", "*.tsx", "*.mjs", "*.cjs"],
      "rules": {
        "import-length-sort/sort": "warn"
      }
    }
  ]
}

Note: The rule automatically skips non-JavaScript files (like .json, .md, etc.) to prevent parsing errors.

Using Recommended Config

{
  "extends": ["plugin:import-length-sort/recommended"]
}

Rule: import-length-sort/sort

Sorts the top-of-file import block by line length in descending order (longest to shortest).

Sorting Strategy

  1. Default-ish imports (default-only, namespace, mixed default+named) are sorted by line length (DESC)
  2. Named-only imports are sorted by line length (DESC)
  3. Side-effect imports are kept at the top by default (configurable)

Options

{
  "import-length-sort/sort": [
    "warn",
    {
      "keepSideEffectAtTop": true
    }
  ]
}
  • keepSideEffectAtTop (boolean, default: true) - When true, side-effect imports (e.g., import './styles.css') stay at the top. When false, they're merged with default imports.

Examples

Before

import { a } from "short";
import defaultExport from "very-long-module-name";
import { foo, bar, baz } from "another-module";

After

import { foo, bar, baz } from "another-module";
import defaultExport from "very-long-module-name";
import { a } from "short";

Why Sort by Length?

Sorting imports by line length (longest to shortest) creates a visually appealing "pyramid" or "descending" structure that:

  • Makes it easier to scan imports at a glance
  • Reduces cognitive load when reviewing code
  • Creates a consistent, predictable ordering

Auto-fix

This rule supports ESLint's --fix option to automatically sort your imports.

eslint --fix .

License

ISC © Saba Silagadze

Contributing

Issues and pull requests are welcome!

Repository

https://github.com/sabasilagadze/eslint-plugin-import-length-sort