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
Specialized rules for TypeScript constructs including union types, intersection types, interfaces, and enums.
Sorts members of TypeScript union types with support for grouping and custom patterns.
/**
* Rule for sorting TypeScript union type members
*/
const sortUnionTypes: Rule.RuleModule;
/**
* Configuration options for sort-union-types rule
*/
interface SortUnionTypesOptions {
/** 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";
/** Newlines between different groups */
newlinesBetween?: "ignore" | "always" | "never" | number;
/** Custom union type groups */
groups?: GroupsOptions<UnionTypeGroup>;
/** Partition unions by comments */
partitionByComment?: PartitionByCommentOption;
/** Partition unions by newlines */
partitionByNewLine?: boolean;
}
type UnionTypeGroup =
| "conditional" | "function" | "import" | "intersection" | "keyword"
| "literal" | "named" | "object" | "operator" | "tuple" | "union"
| "nullish" | "unknown" | string;Usage Examples:
// Sort union types alphabetically
{
"perfectionist/sort-union-types": ["error", {
"type": "alphabetical",
"order": "asc"
}]
}
// Group by type categories
{
"perfectionist/sort-union-types": ["error", {
"groups": [
"named",
"keyword",
"literal",
"function",
"object",
"nullish"
]
}]
}Sorts members of TypeScript intersection types.
/**
* Rule for sorting TypeScript intersection type members
*/
const sortIntersectionTypes: Rule.RuleModule;
/**
* Configuration options for sort-intersection-types rule
*/
interface SortIntersectionTypesOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
newlinesBetween?: "ignore" | "always" | "never" | number;
groups?: GroupsOptions<IntersectionTypeGroup>;
partitionByComment?: PartitionByCommentOption;
partitionByNewLine?: boolean;
}
type IntersectionTypeGroup =
| "conditional" | "function" | "import" | "intersection" | "keyword"
| "literal" | "named" | "object" | "operator" | "tuple" | "union"
| "nullish" | "unknown" | string;Sorts TypeScript interface members with support for method and property grouping.
/**
* Rule for sorting TypeScript interface members
*/
const sortInterfaces: Rule.RuleModule;
/**
* Configuration options for sort-interfaces rule
*/
interface SortInterfacesOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
newlinesBetween?: "ignore" | "always" | "never" | number;
groups?: GroupsOptions<InterfaceGroup>;
customGroups?: CustomGroupsOption<InterfaceSingleCustomGroup>;
partitionByComment?: PartitionByCommentOption;
partitionByNewLine?: boolean;
}
type InterfaceGroup =
| "method" | "property" | "member" | "multiline"
| "optional" | "required" | "unknown" | string;
interface InterfaceSingleCustomGroup {
selector?: InterfaceSelector;
modifiers?: InterfaceModifier[];
elementNamePattern?: RegexOption;
}
type InterfaceSelector = "method" | "property" | "member" | "multiline";
type InterfaceModifier = "optional" | "required" | "multiline";Usage Examples:
// Sort interface members by type
{
"perfectionist/sort-interfaces": ["error", {
"groups": ["method", "property"]
}]
}
// Custom grouping for interfaces
{
"perfectionist/sort-interfaces": ["error", {
"customGroups": [
{
"groupName": "id-fields",
"selector": "property",
"elementNamePattern": "^.*[Ii]d$"
}
]
}]
}Sorts TypeScript enum members with support for different value types.
/**
* Rule for sorting TypeScript enum members
*/
const sortEnums: Rule.RuleModule;
/**
* Configuration options for sort-enums rule
*/
interface SortEnumsOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
sortByValue?: boolean;
forceNumericSort?: boolean;
partitionByComment?: PartitionByCommentOption;
partitionByNewLine?: boolean;
}Usage Examples:
// Sort enum members alphabetically by name
{
"perfectionist/sort-enums": ["error", {
"type": "alphabetical"
}]
}
// Sort enum members by their values
{
"perfectionist/sort-enums": ["error", {
"sortByValue": true,
"forceNumericSort": true
}]
}Sorts TypeScript extends and implements clauses in class and interface declarations.
/**
* Rule for sorting TypeScript heritage clauses (extends/implements)
*/
const sortHeritageClauses: Rule.RuleModule;
/**
* Configuration options for sort-heritage-clauses rule
*/
interface SortHeritageClausesOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
}Usage Examples:
// Sort extends/implements clauses
{
"perfectionist/sort-heritage-clauses": ["error", {
"type": "alphabetical"
}]
}/**
* Base TypeScript sorting configuration
*/
interface TypeScriptSortingOptions {
type?: "alphabetical" | "line-length" | "natural" | "custom";
order?: "asc" | "desc";
ignoreCase?: boolean;
locales?: NonNullable<Intl.LocalesArgument>;
alphabet?: string;
specialCharacters?: "remove" | "trim" | "keep";
}
/**
* Group configuration for TypeScript constructs
*/
type GroupsOptions<T> = (
| (GroupNewlinesBetweenOption & GroupCommentAboveOption)
| GroupNewlinesBetweenOption
| GroupCommentAboveOption
| T[]
| T
)[];
interface GroupNewlinesBetweenOption {
newlinesBetween: "ignore" | "always" | "never" | number;
}
interface GroupCommentAboveOption {
commentAbove: string;
}
/**
* Custom group configuration for TypeScript constructs
*/
type CustomGroupsOption<SingleCustomGroup = object> = ({
newlinesInside?: "always" | "never" | number;
fallbackSort?: FallbackSortOption;
order?: "asc" | "desc";
groupName: string;
type?: "alphabetical" | "line-length" | "natural" | "custom";
} & (AnyOfCustomGroup<SingleCustomGroup> | SingleCustomGroup))[];
interface AnyOfCustomGroup<SingleCustomGroup> {
anyOf: SingleCustomGroup[];
}
interface FallbackSortOption {
order?: "asc" | "desc";
type: "alphabetical" | "line-length" | "natural" | "custom";
}
/**
* Regex pattern for matching TypeScript elements
*/
type RegexOption = SingleRegexOption[] | SingleRegexOption;
type SingleRegexOption =
| {
pattern: string;
flags?: string;
}
| string;
/**
* Partition by comment configuration
*/
type PartitionByCommentOption =
| {
block?: RegexOption | boolean;
line?: RegexOption | boolean;
}
| RegexOption
| boolean;