Skip to content

Commit 4789764

Browse files
committed
fix: fix getting enum members in eslint v8
1 parent 8336207 commit 4789764

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rules/sort-enums.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { TSESTree } from '@typescript-eslint/types'
2+
13
import type { SortingNode } from '../typings'
24

35
import { isPartitionComment } from '../utils/is-partition-comment'
@@ -88,9 +90,13 @@ export default createEslintRule<Options, MESSAGE_ID>({
8890
],
8991
create: context => ({
9092
TSEnumDeclaration: node => {
93+
let getMembers = (nodeValue: TSESTree.TSEnumDeclaration) =>
94+
/* v8 ignore next 2 */
95+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
96+
node.body.members || nodeValue.members
9197
if (
92-
node.body.members.length > 1 &&
93-
node.body.members.every(({ initializer }) => initializer)
98+
getMembers(node).length > 1 &&
99+
getMembers(node).every(({ initializer }) => initializer)
94100
) {
95101
let options = complete(context.options.at(0), {
96102
partitionByComment: false,
@@ -102,7 +108,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
102108
let sourceCode = getSourceCode(context)
103109
let partitionComment = options.partitionByComment
104110

105-
let formattedMembers: SortingNode[][] = node.body.members.reduce(
111+
let formattedMembers: SortingNode[][] = getMembers(node).reduce(
106112
(accumulator: SortingNode[][], member) => {
107113
let comment = getCommentBefore(member, sourceCode)
108114

0 commit comments

Comments
 (0)