1+ import type { TSESTree } from '@typescript-eslint/types'
2+
13import type { SortingNode } from '../typings'
24
35import { 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