sort-class-members
Enforce alphabetical sorting of class members.
Targeted pattern scopeโ
This rule inspects ClassBody members and checks alphabetical order of member
names.
Supported sortable keys:
- identifier keys (
foo) - string literal keys (
"foo")
Members with unsupported/computed names are skipped.
What this rule reportsโ
This rule reports the first class member that appears out of alphabetical order.
Why this rule existsโ
Alphabetical member ordering can reduce merge conflicts and make large classes more predictable to scan.
โ Incorrectโ
class Example {
zebra(): void {}
alpha(): void {}
}
โ Correctโ
class Example {
alpha(): void {}
zebra(): void {}
}
Deprecatedโ
- Lifecycle: Deprecated and frozen.
- Deprecated since:
v1.0.0 - Available until:
v2.0.0 - Use instead:
sort-class-members/sort-class-membersor Perfectionist sorting rules
Behavior and migration notesโ
This rule is deprecated in favor of dedicated sorting plugins.
It reports only and does not provide an autofix.
Optionsโ
This rule has no options.
Statusโ
Use the Deprecated section above for lifecycle details.
Additional examplesโ
class Tokens {
"a-token" = "#000";
"z-token" = "#fff";
}
// โ
valid
class WithComputed {
[dynamicKey](): void {}
alpha(): void {}
}
// computed member names are not directly sortable by this rule
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/sort-class-members": "error",
},
},
];
When not to use itโ
Disable this rule if class member order is semantic (lifecycle grouping, public/private sections) rather than lexical.
Package documentationโ
Rule catalog ID: R067
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.