Skip to main content

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โ€‹

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.