prettier-plugin-sort-members
raw JSON → 0.2.4 verified Sat Apr 25 auth: no javascript
Prettier plugin to sort class, interface, and type alias members (properties, methods, getters/setters) in a configurable order. Current stable version 0.2.4, compatible with Prettier ^3.0.0. Released regularly with bug fixes and features. Differentiators: supports default `@typescript-eslint/member-ordering` order, optional alphabetical sorting, `keepGettersAndSettersTogether`, and experimental `skipSortForSubclassOf` for React component compatibility. Lightweight, no runtime dependencies beyond Prettier.
Common errors
error Error: Cannot find module 'prettier-plugin-sort-members' ↓
cause Plugin not installed or not in node_modules.
fix
Run npm install --save-dev prettier-plugin-sort-members
error Cannot read properties of undefined (reading 'sortMembersAlphabetically') ↓
cause Prettier version < 3.0.0 does not support plugins that use new API.
fix
Upgrade Prettier to ^3.0.0 and ensure prettier-plugin-sort-members is compatible.
error TypeError: prettier.resolveConfig is not a function ↓
cause Plugin being used programmatically with older Prettier API.
fix
Use Prettier's built-in plugin loading via config file or upgrade to Prettier v3.
error ESLint: member-ordering rule conflict with prettier-plugin-sort-members output ↓
cause ESLint enforces a different member order than the plugin produces.
fix
Adjust ESLint member-ordering config to match plugin's order, or disable rule if plugin is used.
Warnings
gotcha Plugin only sorts based on Prettier's output; conflicts with ESLint member-ordering rules may occur if order differs. ↓
fix Align options with ESLint's member-ordering configuration, e.g., set sortMembersAlphabetically to match ESLint's alphabetical ordering.
deprecated skipSortForSubclassOf is experimental and may change in future versions. ↓
fix Use with caution; prefer alternative patterns if stability is required.
breaking Version 0.2.0 introduced keepGettersAndSettersTogether and changed default behavior to couple getters/setters when option is set. Existing configs without this option remain unchanged. ↓
fix If you rely on getters and setters being separated, explicitly set "keepGettersAndSettersTogether": false.
gotcha The plugin sorts literal keys in object types only when sortMembersAlphabetically is true. ↓
fix Set sortMembersAlphabetically to true if you want alphabetical sorting of keys in type/interface literals.
Install
npm install prettier-plugin-sort-members yarn add prettier-plugin-sort-members pnpm add prettier-plugin-sort-members Imports
- default (plugin registration) wrong
// Incorrect: adding as regular module importcorrect// In prettierrc: { "plugins": ["prettier-plugin-sort-members"] }
Quickstart
// 1. Install
npm install --save-dev prettier-plugin-sort-members
// 2. In .prettierrc:
{
"plugins": ["prettier-plugin-sort-members"],
"sortMembersAlphabetically": true,
"keepGettersAndSettersTogether": true
}
// 3. Example input:
class MyClass {
d(): void {}
e: null;
c: string;
a(): void {}
b: number;
constructor() {}
}
// 4. Run prettier (format will sort members alphabetically, but keep getters/setters together):
// After formatting, members will be ordered by: static, instance, constructor, methods, with alphabetical sub-ordering