CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-eslint-plugin-perfectionist

ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

collection-rules.mddocs/

Collection Rules

Rules for sorting arrays, Sets, Maps, and switch cases.

Capabilities

Sort Array Includes

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
  }]
}

Sort Sets

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"
  }]
}

Sort Maps

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"
  }]
}

Sort Switch Case

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"
  }]
}

Types

Collection Sorting Types

/**
 * 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() method
  • sort-sets: Applies to new Set([...]) constructor calls with array argument
  • sort-maps: Applies to new Map([...]) constructor calls with entries array
  • sort-switch-case: Sorts case labels, maintaining the original case block contents

Supported Sorting Strategies:

  • alphabetical: Standard string comparison sorting
  • natural: Human-friendly natural sorting (e.g., "item2" before "item10")
  • line-length: Sort by the length of the line/element
  • custom: Use custom alphabet for sorting order

docs

alphabet-utility.md

class-module-rules.md

collection-rules.md

import-export-rules.md

index.md

jsx-variable-rules.md

object-rules.md

plugin-configuration.md

typescript-rules.md

tile.json