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.

testing
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.

Default import works for both ESM and CJS; require also works but ESM is recommended for flat config.

import sortClassMembers from 'eslint-plugin-sort-class-members'

The rule is accessed via the plugin's rules object; there is no named export for the rule.

import { rules } from 'eslint-plugin-sort-class-members'; rules['sort-class-members']

Flat config can be used directly; avoid manually specifying plugin object when using the recommended config.

import sortClassMembers from 'eslint-plugin-sort-class-members'; export default [sortClassMembers.configs['flat/recommended']]

Plugin exports an object with `rules`, `configs`, and default export; no named export `sortClassMembers` in CJS.

const rules = require('eslint-plugin-sort-class-members').rules

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 footguns
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.
deprecatedThe `groups` configuration property referencing `[everything-else]` is deprecated; use a custom group or omit.
gotchaUsing regex in the `name` property requires the string to start and end with `/`. If not, it is treated as an exact match.
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.
breakingIn ESLint >=9.0.0, flat config is the default; using `.eslintrc` files may cause issues. The plugin supports both.
gotchaThe `accessorPairPositioning` option can cause false positives if get/set pairs are not syntactically adjacent but logically belong together (e.g., in different sections).
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
bingbot
1
Resources