Skip to content

Commit

Permalink
feat: add static-private-method group for sort-classes rule
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Sep 12, 2023
1 parent f4d6fac commit 37512c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/rules/sort-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ This rule accepts an options object with the following properties:

```ts
type Group =
| 'static-private-method'
| 'private-property'
| 'static-property'
| 'index-signature'
Expand Down Expand Up @@ -173,6 +174,7 @@ If you use [one of the configs](/configs/) exported by this plugin, you get the
"constructor",
"static-method",
"private-method",
"static-private-method",
"method",
["get-method", "set-method"],
"unknown"
Expand Down
14 changes: 12 additions & 2 deletions rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { compare } from '../utils/compare'
type MESSAGE_ID = 'unexpectedClassesOrder'

type Group =
| 'static-private-method'
| 'private-property'
| 'static-property'
| 'index-signature'
Expand Down Expand Up @@ -127,11 +128,20 @@ export default createEslintRule<Options, MESSAGE_ID>({
defineGroup('constructor')
}

if (member.accessibility === 'private' || isPrivate) {
let isPrivateMethod =
member.accessibility === 'private' || isPrivate

let isStaticMethod = member.static

if (isPrivateMethod && isStaticMethod) {
defineGroup('static-private-method')
}

if (isPrivateMethod) {
defineGroup('private-method')
}

if (member.static) {
if (isStaticMethod) {
defineGroup('static-method')
}

Expand Down

0 comments on commit 37512c9

Please sign in to comment.