From 1ae9933e7dc26ec188b004e8987f452c2773c068 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sun, 1 Nov 2015 03:29:23 +0300 Subject: [PATCH] printer: only align list items if items have comments --- printer/nodes.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/printer/nodes.go b/printer/nodes.go index 2b8d6ae..abd85c1 100644 --- a/printer/nodes.go +++ b/printer/nodes.go @@ -402,8 +402,14 @@ func (p *printer) list(l *ast.ListType) []byte { buf.WriteString(",") if lit, ok := item.(*ast.LiteralType); ok && lit.LineComment != nil { - for i := 0; i < longestLine-curLen+1; i++ { - buf.WriteByte(blank) + // if the next item doesn't have any comments, do not align + buf.WriteByte(blank) // align one space + if i != len(l.List)-1 { + if lit, ok := l.List[i+1].(*ast.LiteralType); ok && lit.LineComment != nil { + for i := 0; i < longestLine-curLen; i++ { + buf.WriteByte(blank) + } + } } for _, comment := range lit.LineComment.List {