ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Rules for sorting arrays, Sets, Maps, and switch cases.
Sorts arguments in Array.prototype.includes() method calls.
/**
* Rule for sorting Array.includes() method arguments
*/
const sortArrayIncludes: Rule.RuleModule;
/**
* Configuration options for sort-array-includes rule
*/
interface SortArrayIncludesOptions {
/** Sorting strategy */
type?: "alphabetical" | "line-length" | "natural" | "custom";
/** Sort direction */
order?: "asc" | "desc";
/** Case sensitivity for sorting */
ignoreCase?: boolean;
/** Locale for sorting */
locales?: NonNullable<Intl.LocalesArgument>;
/** Custom alphabet for sorting */
alphabet?: string;
/** How to handle special characters */
specialCharacters?: "remove" | "trim" | "keep";
/** Spread elements handling */
spreadLast?: boolean;
}Usage Examples:
// Sort array.includes() arguments alphabetically
{
"perfectionist/sort-array-includes": ["error", {
"type": "alphabetical",
"order": "asc"
}]
}
// Keep spread elements at the end
{
"perfectionist/sort-array-includes": ["error", {
"spreadLast": true
}]
}Sorts values in Set constructor calls.
/**
* Rule for sorting Set constructor values
*/
const sortSets: Rule.RuleModule;
/**
* Configuration options for sort-sets rule
*/
interface SortSetsOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
spreadLast?: boolean;
}Usage Examples:
// Sort Set values alphabetically
{
"perfectionist/sort-sets": ["error", {
"type": "alphabetical"
}]
}
// Sort by line length, longest first
{
"perfectionist/sort-sets": ["error", {
"type": "line-length",
"order": "desc"
}]
}Sorts entries in Map constructor calls.
/**
* Rule for sorting Map constructor entries
*/
const sortMaps: Rule.RuleModule;
/**
* Configuration options for sort-maps rule
*/
interface SortMapsOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
}Usage Examples:
// Sort Map entries by key
{
"perfectionist/sort-maps": ["error", {
"type": "natural",
"order": "asc"
}]
}Sorts case statements in switch blocks with support for default case positioning.
/**
* Rule for sorting switch case statements
*/
const sortSwitchCase: Rule.RuleModule;
/**
* Configuration options for sort-switch-case rule
*/
interface SortSwitchCaseOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
/** Position of default case */
defaultCase?: "first" | "last";
}Usage Examples:
// Sort switch cases with default last
{
"perfectionist/sort-switch-case": ["error", {
"type": "alphabetical",
"defaultCase": "last"
}]
}
// Sort by natural order with default first
{
"perfectionist/sort-switch-case": ["error", {
"type": "natural",
"defaultCase": "first"
}]
}/**
* Base collection sorting configuration
*/
interface CollectionSortingOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
}
/**
* Extended options for array-like collections
*/
interface ArrayCollectionSortingOptions extends CollectionSortingOptions {
/** Whether to place spread elements at the end */
spreadLast?: boolean;
}
/**
* Switch case specific options
*/
interface SwitchCaseSortingOptions extends CollectionSortingOptions {
/** Position of the default case */
defaultCase?: "first" | "last";
}
/**
* Special characters handling strategy
*/
type SpecialCharactersOption = "remove" | "trim" | "keep";
/**
* Sorting type options
*/
type TypeOption = "alphabetical" | "line-length" | "natural" | "custom";
/**
* Sort direction options
*/
type OrderOption = "asc" | "desc";Usage Notes:
sort-array-includes: Only applies to direct calls to array.includes() methodsort-sets: Applies to new Set([...]) constructor calls with array argumentsort-maps: Applies to new Map([...]) constructor calls with entries arraysort-switch-case: Sorts case labels, maintaining the original case block contentsSupported Sorting Strategies: