diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go index b7b17d6be48..27dbddf2c09 100644 --- a/cmd/cue/cmd/get_go.go +++ b/cmd/cue/cmd/get_go.go @@ -529,7 +529,9 @@ func (e *extractor) extractPkg(root string, p *packages.Package) error { addDoc(f.Doc, pkg) f := &cueast.File{Decls: []cueast.Decl{ - internal.NewComment(false, "Code generated by cue get go. DO NOT EDIT."), + &cueast.CommentGroup{List: []*cueast.Comment{ + {Text: "// Code generated by cue get go. DO NOT EDIT."}, + }}, &cueast.CommentGroup{List: []*cueast.Comment{ {Text: "//cue:generate cue get go " + args}, }}, diff --git a/cue/ast/astutil/sanitize_test.go b/cue/ast/astutil/sanitize_test.go index ab9960c562c..324ab057a40 100644 --- a/cue/ast/astutil/sanitize_test.go +++ b/cue/ast/astutil/sanitize_test.go @@ -101,7 +101,7 @@ a: bar.Min() spec2 := ast.NewImport(nil, "foo/bar") spec3 := ast.NewImport(ast.NewIdent("bar"), "foo") return &ast.File{Decls: []ast.Decl{ - internal.NewComment(false, "File comment"), + &ast.CommentGroup{List: []*ast.Comment{{Text: "// File comment"}}}, &ast.Package{Name: ast.NewIdent("pkg")}, &ast.Field{ Label: ast.NewIdent("a"), diff --git a/cue/format/format.go b/cue/format/format.go index 4f257f60b5e..39d0357d65a 100644 --- a/cue/format/format.go +++ b/cue/format/format.go @@ -313,13 +313,12 @@ func (f *formatter) visitComments(until int8) { func (f *formatter) printComment(cg *ast.CommentGroup) { f.Print(cg) - printBlank := false if cg.Doc && len(f.output) > 0 { f.Print(newline) - printBlank = true } for _, c := range cg.List { - if !printBlank { + if f.pos.Column > 1 { + // Vertically align inline comments. f.Print(vtab) } f.Print(c.Slash) diff --git a/cue/format/testdata/comments.txtar b/cue/format/testdata/comments.txtar index 41149dcf5e6..b48f018ca42 100644 --- a/cue/format/testdata/comments.txtar +++ b/cue/format/testdata/comments.txtar @@ -334,10 +334,10 @@ foo: [ -- comment_alone.golden -- // Just one comment on its own. -- comment_field.input -- -// Just one comment on a field. TODO(mvdan): do not indent. +// Just one comment on a field. foo: string -- comment_field.golden -- - // Just one comment on a field. TODO(mvdan): do not indent. +// Just one comment on a field. foo: string -- comments_alone.input -- // Just a few comments diff --git a/cue/format/testdata/expressions.txtar b/cue/format/testdata/expressions.txtar index 5cc2accbba3..fa53c3c5a37 100644 --- a/cue/format/testdata/expressions.txtar +++ b/cue/format/testdata/expressions.txtar @@ -589,7 +589,7 @@ _foo: { // skip_create_image: true } -- issue2496.golden -- - // TODO(mvdan): we indent the list elements too much. +// TODO(mvdan): we indent the list elements too much. machine_type: [ if arch == "amd" {"n2-standard-2"}, if arch == "arm" {"t2a-standard-2"}, diff --git a/encoding/protobuf/jsonpb/testdata/decoder/null.txtar b/encoding/protobuf/jsonpb/testdata/decoder/null.txtar index 64a55376eb0..d0fb5b531bc 100644 --- a/encoding/protobuf/jsonpb/testdata/decoder/null.txtar +++ b/encoding/protobuf/jsonpb/testdata/decoder/null.txtar @@ -88,7 +88,7 @@ a9: null // comment a10 a10: null -- out/jsonpb/data.yaml -- - // comment a0 +// comment a0 a0: 0 // comment a1 @@ -121,7 +121,7 @@ a9: true // comment a10 a10: null -- out/jsonpb/data.cue -- - // comment a0 +// comment a0 a0: 0 // comment a1 diff --git a/internal/core/export/testdata/main/disjunction.txtar b/internal/core/export/testdata/main/disjunction.txtar index c40b98995d5..2510deb5cc3 100644 --- a/internal/core/export/testdata/main/disjunction.txtar +++ b/internal/core/export/testdata/main/disjunction.txtar @@ -4,7 +4,7 @@ a: *1 | int b: *2 | int c: *(a & b) | 3 -- out/definition -- - // Issue #950 +// Issue #950 a: *1 | int b: *2 | int c: *(a & b) | 3 diff --git a/internal/core/export/testdata/selfcontained/import.txtar b/internal/core/export/testdata/selfcontained/import.txtar index af8afeaa798..3ad4a147250 100644 --- a/internal/core/export/testdata/selfcontained/import.txtar +++ b/internal/core/export/testdata/selfcontained/import.txtar @@ -137,7 +137,7 @@ diff old new +++ new @@ -1,10 +1,7 @@ import "tool/exec" - + // Can be inlined. -v: { - x: 3 diff --git a/pkg/math/testdata/mult.txtar b/pkg/math/testdata/mult.txtar index 77f39f78207..c8bb91c316c 100644 --- a/pkg/math/testdata/mult.txtar +++ b/pkg/math/testdata/mult.txtar @@ -12,7 +12,7 @@ f1: math.MultipleOf(5555555, 2) f2: math.MultipleOf(100.01, 4) -- out/math -- - // should be true +// should be true t1: true t2: true t3: true