Registry / testing / eslint-plugin-sort-class-members

eslint-plugin-sort-class-members

JSON →
library1.22.1jsnpmunverified

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-members
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-SORT
E
eslint-plugin-sort-class-members
testingjavascriptv1.22.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sortClassMembers
import sortClassMembers from 'eslint-plugin-sort-class-members'
const sortClassMembers = require('eslint-plugin-sort-class-members')
Default import works for both ESM and CJS; require also works but ESM is recommended for flat config.
sort-class-members/sort-class-members
import { rules } from 'eslint-plugin-sort-class-members'; rules['sort-class-members']
import { sort-class-members } from 'eslint-plugin-sort-class-members'
The rule is accessed via the plugin's rules object; there is no named export for the rule.
flat/recommended config
import sortClassMembers from 'eslint-plugin-sort-class-members'; export default [sortClassMembers.configs['flat/recommended']]
export default [{ plugins: { 'sort-class-members': sortClassMembers }, rules: { 'sort-class-members/sort-class-members': 'error' } }]
Flat config can be used directly; avoid manually specifying plugin object when using the recommended config.
rules (CommonJS)
const rules = require('eslint-plugin-sort-class-members').rules
const { sortClassMembers } = require('eslint-plugin-sort-class-members')
Plugin exports an object with `rules`, `configs`, and default export; no named export `sortClassMembers` in CJS.

Shows installation, ESLint configuration with default order, and a valid class example using the default rule settings.

// Install: npm install eslint eslint-plugin-sort-class-members --save-dev // .eslintrc.json { "plugins": ["sort-class-members"], "rules": { "sort-class-members/sort-class-members": [ "error", { "order": [ "[static-properties]", "[static-methods]", "[properties]", "[conventional-private-properties]", "constructor", "[methods]", "[conventional-private-methods]" ], "accessorPairPositioning": "getThenSet" } ] } } // Valid class (default order) class Example { static myStaticProp = 1; static myStaticMethod() {} myProp = 2; #privateProp = 3; constructor() {} myMethod() {} #privateMethod() {} }
Debug
Known issues
gotchaClass properties require a custom parser like babel-eslint or @typescript-eslint/parser. Without it, properties may not be recognized and may cause false positives.
fix
Use a parser that supports class properties: parser: '@typescript-eslint/parser' or 'babel-eslint'.
affects: >=1.0.0
deprecatedThe `groups` configuration property referencing `[everything-else]` is deprecated; use a custom group or omit.
fix
Define named groups explicitly in the `groups` object instead of relying on built-in 'everything-else'.
affects: >=1.16.0
gotchaUsing regex in the `name` property requires the string to start and end with `/`. If not, it is treated as an exact match.
fix
Use '/pattern/' for regex matching; e.g., '/on.+/' matches names starting with 'on'.
affects: >=1.0.0
breakingESLint flat config support requires version >=1.20.0. Older versions do not have the `flat/recommended` config and will break when used with flat config.
fix
Update the plugin to >=1.20.0 and use `import sortClassMembers from 'eslint-plugin-sort-class-members'; export default [sortClassMembers.configs['flat/recommended']]`.
affects: >=1.20.0
breakingIn ESLint >=9.0.0, flat config is the default; using `.eslintrc` files may cause issues. The plugin supports both.
fix
Migrate to flat config if using ESLint >=9, or continue using legacy config with ESLint <9.
affects: >=1.20.0
gotchaThe `accessorPairPositioning` option can cause false positives if get/set pairs are not syntactically adjacent but logically belong together (e.g., in different sections).
fix
Set `accessorPairPositioning` to 'any' to allow any ordering, or ensure pairs are placed according to chosen positioning.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getSourceCode')
Using an outdated version of the plugin with ESLint >=9 that removes context.getSourceCode().
fix
Update eslint-plugin-sort-class-members to v1.22.0 or later.
ESLint configuration error: Configuration for rule "sort-class-members/sort-class-members" is invalid. Value [2, {...}] must be an array.
Using severity number 2 instead of string 'error' or 'warn' in flat config.
fix
Use severity as string: 'error' or 'warn'; for example: ["error", {...}].
Parsing error: Unexpected token =
Class properties syntax not supported without a appropriate parser.
fix
Add parser: '@typescript-eslint/parser' or 'babel-eslint' to ESLint config.
Error: Failed to load plugin 'sort-class-members' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-sort-class-members'
Plugin not installed or not in node_modules.
fix
Run 'npm install eslint-plugin-sort-class-members --save-dev'.
Upgrade
Version history
1.22.1latest on npm
Audit
Dependencies
eslintrequiredpeer dependency required to run the plugin
Agent activity
6 hits · last 30 days
node
6
Resources
eslint-plugin-sort-class-members — npm install eslint-plugin-sort-class-members · libregistry