Skip to content

Commit 951dedd

Browse files
author
Stephen Gutekanst
committed
format composite literals by breaking lines >50 chars
This helps substantially with readability in some cases, e.g. [see this](https://gist.github.com/slimsag/d43966264de8ab16b24c282aecd41409) Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
1 parent 9f42e56 commit 951dedd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

format_composite_literals.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ func formatCompositeLiterals(input []rune) []rune {
55
inStringLiteral, inRawStringLiteral bool
66
depth int
77
breakFields bool
8+
lineWidth int
89
result []rune
910
)
1011
for i, r := range input {
@@ -23,6 +24,9 @@ func formatCompositeLiterals(input []rune) []rune {
2324
}
2425
if r == '\n' {
2526
depth = 0
27+
lineWidth = 0
28+
} else {
29+
lineWidth++
2630
}
2731
result = append(result, r)
2832
default:
@@ -38,6 +42,12 @@ func formatCompositeLiterals(input []rune) []rune {
3842
}
3943
if r == '\n' {
4044
depth = 0
45+
lineWidth = 0
46+
} else {
47+
lineWidth++
48+
}
49+
if lineWidth >= 50 {
50+
breakFields = true
4151
}
4252
if r == ',' && breakFields {
4353
result = append(result, r)

0 commit comments

Comments
 (0)