# eslint-plugin-sort-class-members

> ESLint rule for enforcing consistent ES6 class member order.

Latest version **1.22.1** (published 2026-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-sort-class-members
pnpm add eslint-plugin-sort-class-members
yarn add eslint-plugin-sort-class-members
bun add eslint-plugin-sort-class-members
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.22.1 |
| Published | 2026-04-02 |
| First published | 2016-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Unpacked size | 36 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 125 |
| Author | Bryan R Smith |
| Maintainers | bryanrsmith |
| Keywords | eslint, eslintplugin, eslint-plugin |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-sort-class-members
- Repository: https://github.com/bryanrsmith/eslint-plugin-sort-class-members
- Issues: https://github.com/bryanrsmith/eslint-plugin-sort-class-members/issues
- npm.io page: https://npm.io/package/eslint-plugin-sort-class-members

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 1.22.1 (latest) — 2026-04-02
- 1.22.0 — 2026-04-01
- 1.21.0 — 2024-10-22
- 1.20.0 — 2024-02-16
- 1.19.0 — 2023-10-03
- 1.18.0 — 2023-05-10
- 1.17.1 — 2023-04-11
- 1.17.0 — 2023-04-05
- 1.16.0 — 2022-12-02
- 1.15.2 — 2022-09-06
- 1.15.1 — 2022-09-05
- 1.15.0 — 2022-09-05
- 1.14.1 — 2021-12-02
- 1.14.0 — 2021-11-02
- 1.13.0 — 2021-11-01
- … 26 more at https://npm.io/package/eslint-plugin-sort-class-members/versions

## README

[![build][ci-image]][ci-url]
[![npm][npm-image]][npm-url]

# eslint-plugin-sort-class-members

ESLint rule for enforcing consistent ES6 class member order.

## Installation

Install [ESLint](http://eslint.org) and `eslint-plugin-sort-class-members`:

```
$ npm install eslint eslint-plugin-sort-class-members --save-dev
```

**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-sort-class-members` globally.

## Usage

Add `sort-class-members` to the plugins section of your `.eslintrc` configuration file, and configure the rule under the rules section.

```json
{
	"plugins": ["sort-class-members"],
	"rules": {
		"sort-class-members/sort-class-members": [
			2,
			{
				"order": [
					"[static-properties]",
					"[static-methods]",
					"[properties]",
					"[conventional-private-properties]",
					"constructor",
					"[methods]",
					"[conventional-private-methods]"
				],
				"accessorPairPositioning": "getThenSet"
			}
		]
	}
}
```

Or, using ESLint's [Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files-new) (`eslint.config.js`):

```js
import sortClassMembers from "eslint-plugin-sort-class-members";

export default [
	// Use the default configuration shown above.
	sortClassMembers.configs["flat/recommended"],

	rules: {
		// Customize specific configuration properties
		"sort-class-members/sort-class-members": [
			2,
			{
				"accessorPairPositioning": "together",
				"stopAfterFirstProblem": true
			}
		]
  }
];
```

When using the default configuration (shown above), the following patterns are considered problems:

```js
class Foo {
	b = 'bar';

	c() {}

	constructor() {} // error Expected constructor to come before method c

	static a() {} // error Expected static method a to come before property b
}
```

When using the default configuration (shown above), the following patterns are not considered problems:

```js
class Foo {
	static a() {}

	b = 'bar';

	constructor() {}

	c() {}
}
```

## Configuration

The rule accepts the following configuration properties:

- `order`: Used to specify the expected sort order of class members.
- `groups`: May optionally be used to created customized named groups of members so that `order` can be more easily maintained. Groups can be referenced by name by using square brackets. E.g., `"[group-name]"`.
- `accessorPairPositioning`: Used to specify the required positioning of get/set pairs. Available values: `getThenSet`, `setThenGet`, `together`, `any`.
- `stopAfterFirstProblem`: Only report the first sort problem in each class (plus the number of problems found). Useful if you only want to know that the class has sort problems without spamming error messages. The default is `false`.
- `locale`: Used to specify the locale for the name comparison method. The default is `en-US`.
- `sortInterfaces`: Used to specify whether to sort TypeScript interfaces as well. The default is `false`.

```js
{
  "order": [
    "constructor",
    "[event-handlers]", // reference the custom group defined in the "groups" property
    "[everything-else]" // a few groups are provided by default (see list below)
  ],
  "groups": {
    "event-handlers": [{ "name": "/on.+/", "type": "method" }]
  },
  "accessorPairPositioning": "getThenSet",
  "stopAfterFirstProblem": false
}
```

Members can be matched to positional slots using several criteria, including name (exact match or regexp), member type (method or property), and whether or not the member is static. Each match slot is described by an object with six properties, all of which are optional.

- `name`: a string matching the name of the member. If the string starts and ends with `/` it will be interpreted as a regular expression. E.g., `"/_.+/"` will match members whose name starts with an underscore.
- `type`: `"method"|"property"`. **Note**: Class properties currently require a custom parser like [babel-eslint](https://github.com/babel/babel-eslint).
- `kind`: `"get"|"set"|"accessor"|"nonAccessor"`. A subtype of `type: "method"` that can match getter or setter methods. `"accessor"` matches both getters and setters, while `"nonAccessor"` matches methods that are neither getters or setters.
- `propertyType`: A subtype of `type: "property"` that can match the type of the property value. e.g., `propertyType: "ArrowFunctionExpression"` to match properties whose value is initialized to an arrow function.
- `accessorPair`: `true|false`. True to match only getters and setters that are part of a pair. i.e., only those that have both `get` and `set` methods defined.
- `static`: `true|false` to restrict the match to static or instance members.
- `private`: `true|false` to restrict the match to [private members](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields). **Note**: Private members currently require a custom parser like [babel-eslint](https://github.com/babel/babel-eslint).
- `accessibility`: `"public"|"private"|"protected"` to restrict the match to members with the specified typescript accessibility modifier. **Note**: Requires `@typescript-eslint/parser`.
- `abstract`: `true|false` to restrict the match to members with typescript `abstract` keyword.
- `override`: `true|false` to restrict the match to members with typescript `override` keyword.
- `readonly`: `true|false` to restrict the match to members with typescript `readonly` keyword.
- `async`: `true|false` to restrict the match to async members.
- `sort`: `"alphabetical"|"none"`. Used to require a specific sorting within the slot for matched members. Defaults to `"none"`.
- `groupByDecorator`: `string|true|false`. A boolean used to indicate whether a property/method should have a decorator or a string used to group properties/methods with the same decorator name (e.g. `observable` for `@observable`). If the string starts and ends with `/` it will be interpreted as a regular expression. E.g., `"/_.+/"` will match members that have a decorator that starts with an underscore. Can be used together with `sort`. **Note**: Decorators are a Stage 2 proposal and require a custom parser like [babel-eslint](https://github.com/babel/babel-eslint).

A few examples:

- `{ "name": "create", "type": "method", "static": true }` would match a static method named `create`.
- `{ "static": true }` would match all static methods and properties.
- `{ "type": "method", "private": true }` would match all private methods.
- `{ "async": true }` would match all async methods.
- `{ "name": "/on.+/", "type": "method" }` would match both static and instance methods whose names start with "on".
- `"/on.+/"` is shorthand for `{ "name": "/on.+/" }`, and would match all static and instance methods and properties whose names start with "on".
- `{ "type": "method", "sort": "alphabetical" }` would match all methods, and enforce an alphabetical sort.

**Note**: You can simply use a string if you only want to match on the name.

The following groups are provided by default:

- `[properties]`: matches all properties
- `[getters]`: matches all getter methods
- `[setters]`: matches all setter methods
- `[accessor-pairs]`: matches getters and setters that are part of a pair (where both `get` and `set` methods are defined)
- `[static-properties]`: matches all static properties
- `[conventional-private-properties]`: matches properties whose name starts with an underscore
- `[arrow-function-properties]`: matches properties whose value is initialized to an arrow function
- `[methods]`: matches all methods
- `[static-methods]`: matches all static methods
- `[async-methods]`: matches all async methods
- `[conventional-private-methods]`: matches methods whose name starts with an underscore
- `[everything-else]`: matches all class members not matched by any other rule

**NOTE**: Currently only class properties using the proposed syntax are matched by `"type": "property"`. Properties added via assignment are not considered by this rule.

## Acknowledgements

Inspired by the `sort-comp` rule from [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react).

[ci-image]: https://img.shields.io/github/actions/workflow/status/bryanrsmith/eslint-plugin-sort-class-members/ci.yaml?branch=main&style=flat-square
[ci-url]: https://github.com/bryanrsmith/eslint-plugin-sort-class-members/actions
[npm-image]: https://img.shields.io/npm/v/eslint-plugin-sort-class-members.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/eslint-plugin-sort-class-members

---
_Source: https://npm.io/package/eslint-plugin-sort-class-members · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
