MCPcopy
hub / github.com/hashicorp/hcl / formatCells

Function formatCells

hclwrite/format.go:159–221  ·  view source on GitHub ↗
(lines []formatLine)

Source from the content-addressed store, hash-verified

157}
158
159func formatCells(lines []formatLine) {
160 chainStart := -1
161 maxColumns := 0
162
163 // We'll deal with the "assign" cell first, since moving that will
164 // also impact the "comment" cell.
165 closeAssignChain := func(i int) {
166 for _, chainLine := range lines[chainStart:i] {
167 columns := chainLine.lead.Columns()
168 spaces := (maxColumns - columns) + 1
169 chainLine.assign[0].SpacesBefore = spaces
170 }
171 chainStart = -1
172 maxColumns = 0
173 }
174 for i, line := range lines {
175 if line.assign == nil {
176 if chainStart != -1 {
177 closeAssignChain(i)
178 }
179 } else {
180 if chainStart == -1 {
181 chainStart = i
182 }
183 columns := line.lead.Columns()
184 if columns > maxColumns {
185 maxColumns = columns
186 }
187 }
188 }
189 if chainStart != -1 {
190 closeAssignChain(len(lines))
191 }
192
193 // Now we'll deal with the comments
194 closeCommentChain := func(i int) {
195 for _, chainLine := range lines[chainStart:i] {
196 columns := chainLine.lead.Columns() + chainLine.assign.Columns()
197 spaces := (maxColumns - columns) + 1
198 chainLine.comment[0].SpacesBefore = spaces
199 }
200 chainStart = -1
201 maxColumns = 0
202 }
203 for i, line := range lines {
204 if line.comment == nil {
205 if chainStart != -1 {
206 closeCommentChain(i)
207 }
208 } else {
209 if chainStart == -1 {
210 chainStart = i
211 }
212 columns := line.lead.Columns() + line.assign.Columns()
213 if columns > maxColumns {
214 maxColumns = columns
215 }
216 }

Callers 1

formatFunction · 0.85

Calls 1

ColumnsMethod · 0.80

Tested by

no test coverage detected