
eslint-plugin-pretty-imports
https://github.com/dmtrKovalenko/eslint-plugin-pretty-imports- Category
- Developer Tools
- Rank
- No. 1508Tools index
Previous survey · No. 1515 ·
- Pricing
- Open Source
- Type
- TOOL
- Builder
- dmtrKovalenko
- GitHub
- 207 stars
- Latest release
- v1.3.0
- Date
About
ESLint plugin that sorts and groups your JavaScript imports so your file headers stop looking chaotic.
What it does
It checks import declarations against an opinionated ordering model, then offers automatic fixes. Side-effect, namespace, default, and named forms receive separate priority groups. Within groups, it can compare full statement length or specifier length. A second exported rule reorders specifiers inside individual declarations.
Why it's ranked here
The tool has a narrow, understandable job and implements it through ESLint’s normal reporting and fixing flow. Its strongest case is deterministic enforcement with little configuration. The verdict is mixed, however, because the default length-based policy is visual rather than semantic, and the documentation understates the available rule surface.
What's good
Automatic fixes preserve source text and explicitly account for leading and same-line trailing comments. Options can disable within-group length sorting or use specifier length instead. Tests cover basic ordering, comments, intervening non-import statements, disabled length sorting, and specifier reordering. Files without imports produce no report.
Tradeoffs
Its import categories are fixed, and the available options only adjust length-based behavior. The main fixer can collect non-import nodes found between imports and move them after the import block, which is broader than merely reordering declarations. Specifiers are sorted by source-text length, not alphabetically. The README says the plugin provides one rule, while the exported rule map contains two.
How to use it well
Use it in a TypeScript or JavaScript project already enforcing style through ESLint, especially when the team accepts its category order and wants fixes applied during linting. Start with warnings and inspect changes around comments or statements placed between imports. Pair it with Prettier for general formatting. It does not provide broad formatting or customizable import-group policies.
Technical notes+
package.json defines a TypeScript build, Jest tests through ts-jest, an ESLint plugin package entry, and an MIT license. src/index.ts exports sorted and sorted-specifiers. src/rules/sorted.ts visits the Program, gathers imports plus intervening nodes, computes numeric sort indexes, and replaces the covered source range. src/rules/sorted-specifiers.ts visits each ImportDeclaration and replaces the specifier range. src/services/imports.ts assigns base priorities 1 through 4 by first specifier type, adds length divided by 100 unless disabled, and treats mixed default-plus-named imports according to the first specifier. src/services/eslint.ts reconstructs node text with leading and same-line trailing comments. jest.config.js targets TypeScript specs under __tests__.
Observed
- License
- MIT
- Primary language
- TypeScript source compiled with the TypeScript compiler
- Packaging
- Published as an npm package and documented for development installation with npm or Yarn
- Interface
- ESLint plugin exporting two fixable rules
- Runtime declaration
- Package manifest declares Node.js 0.10 or newer
- Test structure
- Jest and ESLint RuleTester suites cover rules and import sorting services
Read from README.md, package.json, src/index.ts, src/rules/sorted.ts, src/services/eslint.ts, src/services/imports.ts, src/constants/messages.ts, src/rules/sorted-specifiers.ts, jest.config.js, __tests__/rule-tester.ts, __tests__/rules/sorted.spec.ts, __tests__/services/imports.spec.ts, __tests__/rules/sorted-specifiers.spec.ts, __tests__/rules/sorted-with-comments.spec.ts, __tests__/rules/sorted-no-line-length.spec.ts.
What it can do
Sort JavaScript import statements
JavaScript file with unsorted imports → JavaScript file with alphabetically sorted imports
Group JavaScript imports by type
JavaScript file with mixed import types → JavaScript file with imports grouped by categories (external packages, internal modules, etc.)
Lint import organization
JavaScript file with chaotic import ordering → ESLint error reports for improperly organized imports
Auto-fix import formatting
JavaScript file with disorganized imports → JavaScript file with properly formatted and organized imports
Enforce import grouping rules
JavaScript codebase → Consistent import organization across all files
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.