Get rid of some extra newlines in bpfmt

Bug: 323382414
Test: go tests, and I also ran both the old/new bpfmts on the whole aosp source tree, and the only difference between the results was one extra removed line in external/uwb
Change-Id: I4942c9247a66f1de5028de39caa5cd34b66093c3
This commit is contained in:
Cole Faust 2024-03-19 16:41:14 -07:00
parent a962edf763
commit d2f1141871
2 changed files with 5 additions and 7 deletions

View file

@ -144,6 +144,7 @@ func (p *printer) printSelect(s *Select) {
}
if len(s.Cases) == 1 && s.Cases[0].Pattern.Value == "__soong_conditions_default__" {
p.printExpression(s.Cases[0].Value)
p.pos = s.RBracePos
return
}
p.requestSpace()
@ -317,8 +318,8 @@ func (p *printer) printEndOfLineCommentsBefore(pos scanner.Position) {
if len(p.skippedComments) > 0 {
for _, c := range p.skippedComments {
p.printComment(c)
}
p._requestNewline()
}
p.skippedComments = nil
}
for p.curComment < len(p.comments) && p.comments[p.curComment].Pos().Line < pos.Line {
@ -406,9 +407,11 @@ func (p *printer) printComment(cg *CommentGroup) {
p._requestNewline()
}
}
if p.pos.Offset < comment.End().Offset {
p.pos = comment.End()
}
}
}
// Print any comments that occur after the last token, and a trailing newline
func (p *printer) flush() {

View file

@ -281,7 +281,6 @@ module // test
output: `
// test
module { // test
srcs: [
"src1.c",
"src2.c",
@ -356,9 +355,7 @@ test // test
`,
output: `
test { // test
// test
}
`,
},
@ -598,12 +595,10 @@ foo {
}),
}
`,
// TODO(b/323382414): This shouldn't have an empty newline after stuff
output: `
// test
foo {
stuff: "c2", // test2
}
`,
},