An ESLint plugin that enforces consistent ordering of ES6 class members, with support for TypeScript interfaces, accessor pairs, decorators, and custom grouping via configuration. Current stable version is 1.22.1, released in 2024. Maintained actively with periodic updates. Key differentiators include fine-grained matching (by name, type, kind, static, decorator), built-in support for conventional private members, and compatibility with ESLint flat config. Unlike generic sorting rules, it allows complex order specifications and groups like event-handlers or everything-else.
npm install eslint-plugin-sort-class-membersVerified import paths — ran on the pinned version, not inferred.
Shows installation, ESLint configuration with default order, and a valid class example using the default rule settings.
Use a parser that supports class properties: parser: '@typescript-eslint/parser' or 'babel-eslint'.
Define named groups explicitly in the `groups` object instead of relying on built-in 'everything-else'.
Use '/pattern/' for regex matching; e.g., '/on.+/' matches names starting with 'on'.
Update the plugin to >=1.20.0 and use `import sortClassMembers from 'eslint-plugin-sort-class-members'; export default [sortClassMembers.configs['flat/recommended']]`.
Migrate to flat config if using ESLint >=9, or continue using legacy config with ESLint <9.
Set `accessorPairPositioning` to 'any' to allow any ordering, or ensure pairs are placed according to chosen positioning.
Update eslint-plugin-sort-class-members to v1.22.0 or later.
Use severity as string: 'error' or 'warn'; for example: ["error", {...}].Add parser: '@typescript-eslint/parser' or 'babel-eslint' to ESLint config.
Run 'npm install eslint-plugin-sort-class-members --save-dev'.