Registry / testing / eslint-plugin-perfectionist

eslint-plugin-perfectionist

JSON →
library5.9.0jsnpmunverified

An ESLint plugin that enforces sorting of various data structures including objects, imports, TypeScript types, enums, JSX props, Svelte attributes, and more. Current stable version is 5.9.0 with frequent releases (multiple per month). Supports ESLint v8.45+, v9, and v10. All rules are auto-fixable. Key differentiators: supports multiple sort orders (alphabetical, natural, line-length), highly configurable with group/partition/selector options, and covers broader range of structures than alternatives like eslint-plugin-simple-import-sort or eslint-plugin-import.

npm install eslint-plugin-perfectionist
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-PERF
E
eslint-plugin-perfectionist
testingjavascriptv5.9.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export (plugin object)
import perfectionist from 'eslint-plugin-perfectionist'
const perfectionist = require('eslint-plugin-perfectionist')
Plugin is ESM-only since v3. Use import in flat config; require() will not work in CJS projects.
sort-imports rule
import perfectionist from 'eslint-plugin-perfectionist'; export default [ { plugins: { perfectionist }, rules: { 'perfectionist/sort-imports': 'error' } } ]
module.exports = { rules: { 'perfectionist/sort-imports': 'error' } }
Flat config requires the plugin object in 'plugins' key. Legacy .eslintrc format is deprecated in favor of flat config.
configs (recommended)
import perfectionist from 'eslint-plugin-perfectionist'; export default [...perfectionist.configs['recommended-alphabetical']]
module.exports = { extends: ['plugin:perfectionist/recommended-alphabetical'] }
Configs are exported as arrays for flat config. Legacy 'extends' string works only with old ESLint config format.
sort-objects rule
import perfectionist from 'eslint-plugin-perfectionist'; export default [ { plugins: { perfectionist }, rules: { 'perfectionist/sort-objects': ['error', { type: 'alphabetical' }] } } ]
Each rule accepts options like 'type' (alphabetical, line-length, natural) and custom groups.

Shows flat config setup with recommended alphabetical config and custom sort-imports rule options.

// eslint.config.js import js from '@eslint/js'; import perfectionist from 'eslint-plugin-perfectionist'; export default [ js.configs.recommended, ...perfectionist.configs['recommended-alphabetical'], { rules: { 'perfectionist/sort-imports': ['error', { type: 'alphabetical', order: 'asc', ignoreCase: true, newlinesBetween: 'ignore', groups: [ 'type', 'internal', 'external', 'builtin', 'parent', 'sibling', 'index', 'object', 'style', 'side-effect', 'unknown', ], customGroups: { value: {}, type: {} }, }], }, }, ];
Debug
Known issues
breakingv3 dropped support for ESLint < 8 and CJS configuration.
fix
Upgrade to ESLint v8+ and migrate to flat config (eslint.config.js).
affects: >=3.0.0 <4.0.0
breakingv5 requires Node.js >=20.0.0 or >=22.0.0.
fix
Update Node.js to version 20.x or 22.x.
affects: >=5.0.0
gotchaThe 'sort-imports' rule does not automatically group side-effect imports; they must be explicitly in a 'side-effect' group.
fix
Include 'side-effect' in the 'groups' array if you want side-effect imports sorted separately.
affects: >=3.0.0
gotchaSome rules may conflict with Prettier or other formatters when sorting by line-length.
fix
Use 'alphabetical' type or disable conflicting formatting rules.
affects: >=3.0.0
deprecatedThe legacy .eslintrc format is deprecated; flat config is recommended.
fix
Switch to eslint.config.js flat config.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Failed to load plugin 'perfectionist' declared in 'plugins': Cannot find module 'eslint-plugin-perfectionist'
Missing npm install or incorrect import path in flat config.
fix
Run 'npm install --save-dev eslint-plugin-perfectionist' and ensure import uses correct name.
TypeError: Cannot read properties of undefined (reading 'sort-imports')
Using string rule name without registering plugin object in flat config.
fix
Add 'plugins: { perfectionist }' to the flat config object.
Configuration for rule 'perfectionist/sort-imports' is invalid: Unknown option 'type'
Using option 'type' in legacy config where it may not be recognized.
fix
Update to flat config or use correct options for your version; check documentation.
Error: Requires ESLint >=8.45.0
Installed ESLint version is too old.
fix
Upgrade ESLint to v8.45.0 or higher (v9/v10 also supported).
Cannot find module 'eslint-plugin-perfectionist' or its corresponding type declarations.
Missing TypeScript type declarations; the package ships types, but IDE may not pick them up.
fix
Ensure 'eslint-plugin-perfectionist' is installed and tsconfig.json includes 'node_modules' in 'types' or uses 'skipLibCheck'.
Upgrade
Version history
5.9.0latest on npm
Audit
Dependencies
eslintrequiredpeer dependency, required as the hosting linter
Agent activity
118 hits · last 30 days
node
112
Amazon
1
Resources
eslint-plugin-perfectionist — npm install eslint-plugin-perfectionist · libregistry