Skip to content

Commit c4c740b

Browse files
committed
dont report partially sorted members
1 parent bd6c0e6 commit c4c740b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/utils/reportUtils.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ export function shouldReportUnsorted(
1212
unsortedBody: NodeOrToken[],
1313
nodeInfo: NodePositionInfo,
1414
) {
15-
const { initialIndex, finalIndex } = nodeInfo
16-
const isLastSorted = finalIndex === sortedBody.length - 1
17-
// Node moved and next sorted node isn't the same neighbor as unsorted
18-
return (
19-
initialIndex !== finalIndex &&
20-
(isLastSorted || sortedBody[finalIndex + 1] !== unsortedBody[initialIndex + 1])
21-
)
15+
const { initialIndex: unsortedIndex, finalIndex: sortedIndex } = nodeInfo
16+
const isLastInSorted = sortedIndex === sortedBody.length - 1
17+
const nextSortedNode = sortedBody[sortedIndex + 1]
18+
const nextUnsortedNode = unsortedBody[unsortedIndex + 1]
19+
// is sorted directly with a neighbor or partially sorted (e.g. a B D F E only 2 out of order)
20+
const isPartiallySorted =
21+
nextSortedNode === nextUnsortedNode ||
22+
unsortedBody.indexOf(nextSortedNode) > unsortedIndex
23+
24+
return unsortedIndex !== sortedIndex && (isLastInSorted || !isPartiallySorted)
2225
}
2326

2427
// Helpful metadata on nodes to report/skip reporting

0 commit comments

Comments
 (0)