Add newlines around list of structs am: 0cb1064428

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1977926

Change-Id: I293133c1e09aa79807b3554c9a334e900830a985
This commit is contained in:
Jooyung Han 2022-02-11 00:13:08 +00:00 committed by Automerger Merge Worker
commit d5be0c1c66
2 changed files with 31 additions and 1 deletions

View file

@ -139,7 +139,7 @@ func (p *printer) printExpression(value Expression) {
func (p *printer) printList(list []Expression, pos, endPos scanner.Position) { func (p *printer) printList(list []Expression, pos, endPos scanner.Position) {
p.requestSpace() p.requestSpace()
p.printToken("[", pos) p.printToken("[", pos)
if len(list) > 1 || pos.Line != endPos.Line { if len(list) > 1 || pos.Line != endPos.Line || listHasMap(list) {
p.requestNewline() p.requestNewline()
p.indent(p.curIndent() + 4) p.indent(p.curIndent() + 4)
for _, value := range list { for _, value := range list {
@ -392,3 +392,12 @@ func max(a, b int) int {
return b return b
} }
} }
func listHasMap(list []Expression) bool {
for _, value := range list {
if _, ok := value.(*Map); ok {
return true
}
}
return false
}

View file

@ -426,6 +426,27 @@ stuff {
], ],
], ],
} }
`,
},
{
input: `
// test
stuff {
namespace: "google",
list_of_structs: [{ key1: "a", key2: "b" }],
}
`,
output: `
// test
stuff {
namespace: "google",
list_of_structs: [
{
key1: "a",
key2: "b",
},
],
}
`, `,
}, },
} }