Skip to content

Commit

Permalink
fix: fix getting enum members in eslint v8
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Aug 4, 2024
1 parent 8336207 commit 4789764
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rules/sort-enums.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { TSESTree } from '@typescript-eslint/types'

import type { SortingNode } from '../typings'

import { isPartitionComment } from '../utils/is-partition-comment'
Expand Down Expand Up @@ -88,9 +90,13 @@ export default createEslintRule<Options, MESSAGE_ID>({
],
create: context => ({
TSEnumDeclaration: node => {
let getMembers = (nodeValue: TSESTree.TSEnumDeclaration) =>
/* v8 ignore next 2 */
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
node.body.members || nodeValue.members
if (
node.body.members.length > 1 &&
node.body.members.every(({ initializer }) => initializer)
getMembers(node).length > 1 &&
getMembers(node).every(({ initializer }) => initializer)
) {
let options = complete(context.options.at(0), {
partitionByComment: false,
Expand All @@ -102,7 +108,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
let sourceCode = getSourceCode(context)
let partitionComment = options.partitionByComment

let formattedMembers: SortingNode[][] = node.body.members.reduce(
let formattedMembers: SortingNode[][] = getMembers(node).reduce(
(accumulator: SortingNode[][], member) => {
let comment = getCommentBefore(member, sourceCode)

Expand Down

0 comments on commit 4789764

Please sign in to comment.