Gathering detailed insights and metrics for eslint-plugin-perfectionist-unofficial
Gathering detailed insights and metrics for eslint-plugin-perfectionist-unofficial
☂️ ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
npm install eslint-plugin-perfectionist-unofficial
Typescript
Module System
Node Version
NPM Version
59.6
Supply Chain
89.2
Quality
70.5
Maintenance
100
Vulnerability
96.1
License
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
321
Last Day
2
Last Week
7
Last Month
41
Last Year
194
MIT License
2,346 Stars
689 Commits
45 Forks
9 Watchers
2 Branches
28 Contributors
Updated on Feb 21, 2025
Latest Version
2.0.0
Package Id
eslint-plugin-perfectionist-unofficial@2.0.0
Unpacked Size
95.91 kB
Size
19.79 kB
File Count
11
NPM Version
9.8.1
Node Version
16.20.1
Published on
Jul 31, 2023
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
-41.7%
7
Compared to previous week
Last Month
272.7%
41
Compared to previous month
Last Year
52.8%
194
Compared to previous year
5
4
35
ESLint plugin that sets rules to format your code and make it consistent.
This plugin defines rules for sorting various data, such as objects, imports, TypeScript types, enums, JSX props, Svelte attributes, etc. alphabetically, naturally, or by line length
All rules are automatically fixable. It's safe!
Sorting imports and properties in software development offers numerous benefits:
Readability: Finding declarations in a sorted, large list is a little faster. Remember that you read the code much more often than you write it.
Maintainability: Sorting imports and properties is considered a good practice in software development, contributing to code quality and consistency across the codebase.
Code Review and Collaboration: If you set rules that say you can only do things one way, then no one will have to spend time thinking about how to do it.
Code Uniformity: When all code looks exactly the same, it is very hard to see who wrote it, which makes achieving the lofty goal of collective code ownership easier.
Aesthetics: This not only provides functional benefits, but also gives the code an aesthetic appeal, visually pleasing and harmonious structure. Take your code to the beauty salon!
See docs.
You'll first need to install ESLint:
1npm install --save-dev eslint
Next, install eslint-plugin-perfectionist
:
1npm install --save-dev eslint-plugin-perfectionist
Add eslint-plugin-perfectionist
to the plugins section of the ESLint configuration file and define the list of rules you will use.
.eslintrc
)1{ 2 "plugins": [ 3 "perfectionist" 4 ], 5 "rules": { 6 "perfectionist/sort-objects": [ 7 "error", 8 { 9 "type": "natural", 10 "order": "asc" 11 } 12 ] 13 } 14}
eslint.config.js
) (requires eslint >= v8.23.0)1import perfectionist from 'eslint-plugin-perfectionist' 2 3export default [ 4 { 5 plugins: { 6 perfectionist, 7 }, 8 rules: { 9 'perfectionist/sort-objects': [ 10 'error', 11 { 12 type: 'natural', 13 order: 'asc', 14 }, 15 ], 16 }, 17 }, 18]
The easiest way to use eslint-plugin-perfectionist
is to use ready-made configs. Config files use all the rules of the current plugin, but you can override them.
.eslintrc
)1{ 2 "extends": [ 3 "plugin:perfectionist/recommended-natural" 4 ] 5}
eslint.config.js
)1import perfectionistNatural from 'eslint-plugin-perfectionist/configs/recommended-natural' 2 3export default [ 4 perfectionistNatural, 5]
Name | Description |
---|---|
recommended-alphabetical | all plugin rules with alphabetical sorting in ascending order |
recommended-natural | all plugin rules with natural sorting in ascending order |
recommended-line-length | all plugin rules with sorting by line length in descending order |
🔧 Automatically fixable by the --fix
CLI option.
Name | Description | 🔧 |
---|---|---|
sort-array-includes | enforce sorted arrays before include method | 🔧 |
sort-astro-attributes | enforce sorted Astro attributes | 🔧 |
sort-classes | enforce sorted classes | 🔧 |
sort-enums | enforce sorted TypeScript enums | 🔧 |
sort-exports | enforce sorted exports | 🔧 |
sort-imports | enforce sorted imports | 🔧 |
sort-interfaces | enforce sorted interface properties | 🔧 |
sort-jsx-props | enforce sorted JSX props | 🔧 |
sort-maps | enforce sorted Map elements | 🔧 |
sort-named-exports | enforce sorted named exports | 🔧 |
sort-named-imports | enforce sorted named imports | 🔧 |
sort-object-types | enforce sorted object types | 🔧 |
sort-objects | enforce sorted objects | 🔧 |
sort-svelte-attributes | enforce sorted Svelte attributes | 🔧 |
sort-union-types | enforce sorted union types | 🔧 |
Yes. To do this, you need to enable autofix in ESLint when you save the file in your editor. Instructions for your editor can be found here.
On the whole, yes. We are very careful to make sure that the work of the plugin does not negatively affect the work of the code. For example, the plugin takes into account spread operators in JSX and objects, comments to the code, exports with *
. Safety is our priority. If you encounter any problem, you can create an issue.
I love Prettier. However, this is not his area of responsibility. Prettier is used for formatting, and ESLint is also used for styling. For example, changing the order of imports can affect how the code works (console.log calls, fetch, style loading). Prettier should not change the AST. There is a cool article about this: "The Blurry Line Between Formatting and Style" by @joshuakgoldberg.
There are rules of ESLint and other ESLint plugins that may conflict with the rules of ESLint Plugin Perfectionist. We strongly recommend that you disable rules with similar functionality.
I recommend that you read the documentation before using any rules.
perfectionist/sort-imports:
1{ 2 "rules": { 3 "import/order": "off", 4 "sort-imports": "off" 5 } 6}
perfectionist/sort-interfaces:
1{ 2 "rules": { 3 "@typescript-eslint/adjacent-overload-signatures": "off" 4 } 5}
perfectionist/sort-jsx-props:
1{ 2 "rules": { 3 "react/jsx-sort-props": "off" 4 } 5}
perfectionist/sort-named-imports:
1{ 2 "rules": { 3 "sort-imports": "off" 4 } 5}
perfectionist/sort-object-types:
1{ 2 "rules": { 3 "@typescript-eslint/adjacent-overload-signatures": "off" 4 } 5}
perfectionist/sort-objects:
1{ 2 "rules": { 3 "sort-keys": "off" 4 } 5}
perfectionist/sort-union-types:
1{ 2 "rules": { 3 "@typescript-eslint/sort-type-constituents": "off" 4 } 5}
This plugin is following Semantic Versioning and ESLint's Semantic Versioning Policy.
See Contributing Guide.
@azat-io/eslint-config
- Collection of ESLint configsMIT © Azat S.
No vulnerabilities found.
No security vulnerabilities found.