github.com/hashicorp/hcl/v2@v2.20.0/hclwrite/native_node_sorter.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package hclwrite 5 6 import ( 7 "github.com/hashicorp/hcl/v2/hclsyntax" 8 ) 9 10 type nativeNodeSorter struct { 11 Nodes []hclsyntax.Node 12 } 13 14 func (s nativeNodeSorter) Len() int { 15 return len(s.Nodes) 16 } 17 18 func (s nativeNodeSorter) Less(i, j int) bool { 19 rangeI := s.Nodes[i].Range() 20 rangeJ := s.Nodes[j].Range() 21 return rangeI.Start.Byte < rangeJ.Start.Byte 22 } 23 24 func (s nativeNodeSorter) Swap(i, j int) { 25 s.Nodes[i], s.Nodes[j] = s.Nodes[j], s.Nodes[i] 26 }