{"id":19940,"library":"eslint-plugin-sort-class-members","title":"eslint-plugin-sort-class-members","description":"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.","status":"active","version":"1.22.1","language":"javascript","source_language":"en","source_url":"git://github.com/bryanrsmith/eslint-plugin-sort-class-members","tags":["javascript","eslint","eslintplugin","eslint-plugin"],"install":[{"cmd":"npm install eslint-plugin-sort-class-members","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-sort-class-members","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-sort-class-members","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to run the plugin","package":"eslint","optional":false}],"imports":[{"note":"Default import works for both ESM and CJS; require also works but ESM is recommended for flat config.","wrong":"const sortClassMembers = require('eslint-plugin-sort-class-members')","symbol":"sortClassMembers","correct":"import sortClassMembers from 'eslint-plugin-sort-class-members'"},{"note":"The rule is accessed via the plugin's rules object; there is no named export for the rule.","wrong":"import { sort-class-members } from 'eslint-plugin-sort-class-members'","symbol":"sort-class-members/sort-class-members","correct":"import { rules } from 'eslint-plugin-sort-class-members'; rules['sort-class-members']"},{"note":"Flat config can be used directly; avoid manually specifying plugin object when using the recommended config.","wrong":"export default [{ plugins: { 'sort-class-members': sortClassMembers }, rules: { 'sort-class-members/sort-class-members': 'error' } }]","symbol":"flat/recommended config","correct":"import sortClassMembers from 'eslint-plugin-sort-class-members'; export default [sortClassMembers.configs['flat/recommended']]"},{"note":"Plugin exports an object with `rules`, `configs`, and default export; no named export `sortClassMembers` in CJS.","wrong":"const { sortClassMembers } = require('eslint-plugin-sort-class-members')","symbol":"rules (CommonJS)","correct":"const rules = require('eslint-plugin-sort-class-members').rules"}],"quickstart":{"code":"// Install: npm install eslint eslint-plugin-sort-class-members --save-dev\n\n// .eslintrc.json\n{\n  \"plugins\": [\"sort-class-members\"],\n  \"rules\": {\n    \"sort-class-members/sort-class-members\": [\n      \"error\",\n      {\n        \"order\": [\n          \"[static-properties]\",\n          \"[static-methods]\",\n          \"[properties]\",\n          \"[conventional-private-properties]\",\n          \"constructor\",\n          \"[methods]\",\n          \"[conventional-private-methods]\"\n        ],\n        \"accessorPairPositioning\": \"getThenSet\"\n      }\n    ]\n  }\n}\n\n// Valid class (default order)\nclass Example {\n  static myStaticProp = 1;\n  static myStaticMethod() {}\n  myProp = 2;\n  #privateProp = 3;\n  constructor() {}\n  myMethod() {}\n  #privateMethod() {}\n}","lang":"typescript","description":"Shows installation, ESLint configuration with default order, and a valid class example using the default rule settings."},"warnings":[{"fix":"Use a parser that supports class properties: parser: '@typescript-eslint/parser' or 'babel-eslint'.","message":"Class properties require a custom parser like babel-eslint or @typescript-eslint/parser. Without it, properties may not be recognized and may cause false positives.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Define named groups explicitly in the `groups` object instead of relying on built-in 'everything-else'.","message":"The `groups` configuration property referencing `[everything-else]` is deprecated; use a custom group or omit.","severity":"deprecated","affected_versions":">=1.16.0"},{"fix":"Use '/pattern/' for regex matching; e.g., '/on.+/' matches names starting with 'on'.","message":"Using regex in the `name` property requires the string to start and end with `/`. If not, it is treated as an exact match.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update the plugin to >=1.20.0 and use `import sortClassMembers from 'eslint-plugin-sort-class-members'; export default [sortClassMembers.configs['flat/recommended']]`.","message":"ESLint 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.","severity":"breaking","affected_versions":">=1.20.0"},{"fix":"Migrate to flat config if using ESLint >=9, or continue using legacy config with ESLint <9.","message":"In ESLint >=9.0.0, flat config is the default; using `.eslintrc` files may cause issues. The plugin supports both.","severity":"breaking","affected_versions":">=1.20.0"},{"fix":"Set `accessorPairPositioning` to 'any' to allow any ordering, or ensure pairs are placed according to chosen positioning.","message":"The `accessorPairPositioning` option can cause false positives if get/set pairs are not syntactically adjacent but logically belong together (e.g., in different sections).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Update eslint-plugin-sort-class-members to v1.22.0 or later.","cause":"Using an outdated version of the plugin with ESLint >=9 that removes context.getSourceCode().","error":"TypeError: Cannot read properties of undefined (reading 'getSourceCode')"},{"fix":"Use severity as string: 'error' or 'warn'; for example: [\"error\", {...}].","cause":"Using severity number 2 instead of string 'error' or 'warn' in flat config.","error":"ESLint configuration error: Configuration for rule \"sort-class-members/sort-class-members\" is invalid. Value [2, {...}] must be an array."},{"fix":"Add parser: '@typescript-eslint/parser' or 'babel-eslint' to ESLint config.","cause":"Class properties syntax not supported without a appropriate parser.","error":"Parsing error: Unexpected token ="},{"fix":"Run 'npm install eslint-plugin-sort-class-members --save-dev'.","cause":"Plugin not installed or not in node_modules.","error":"Error: Failed to load plugin 'sort-class-members' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-sort-class-members'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}