hcl/printer: output an equal sign only if we had one originally
This commit is contained in:
parent
3bac6be959
commit
b24dfd1bb1
@ -178,11 +178,13 @@ func (p *printer) objectItem(o *ast.ObjectItem) []byte {
|
|||||||
buf.WriteByte(blank)
|
buf.WriteByte(blank)
|
||||||
|
|
||||||
// reach end of key
|
// reach end of key
|
||||||
if i == len(o.Keys)-1 && len(o.Keys) == 1 {
|
if i == len(o.Keys)-1 {
|
||||||
|
if o.Assign.IsValid() && len(o.Keys) == 1 {
|
||||||
buf.WriteString("=")
|
buf.WriteString("=")
|
||||||
buf.WriteByte(blank)
|
buf.WriteByte(blank)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf.Write(p.output(o.Val))
|
buf.Write(p.output(o.Val))
|
||||||
|
|
||||||
|
4
hcl/printer/testdata/comment.golden
vendored
4
hcl/printer/testdata/comment.golden
vendored
@ -23,7 +23,7 @@ numbers = [1, 2] // another line here
|
|||||||
variable = {
|
variable = {
|
||||||
description = "bar" # another yooo
|
description = "bar" # another yooo
|
||||||
|
|
||||||
foo = {
|
foo {
|
||||||
# Nested standalone
|
# Nested standalone
|
||||||
|
|
||||||
bar = "fatih"
|
bar = "fatih"
|
||||||
@ -31,6 +31,6 @@ variable = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lead comment
|
// lead comment
|
||||||
foo = {
|
foo {
|
||||||
bar = "fatih" // line comment 2
|
bar = "fatih" // line comment 2
|
||||||
} // line comment 3
|
} // line comment 3
|
2
hcl/printer/testdata/comment_aligned.golden
vendored
2
hcl/printer/testdata/comment_aligned.golden
vendored
@ -1,4 +1,4 @@
|
|||||||
aligned = {
|
aligned {
|
||||||
# We have some aligned items below
|
# We have some aligned items below
|
||||||
foo = "fatih" # yoo1
|
foo = "fatih" # yoo1
|
||||||
default = "bar" # yoo2
|
default = "bar" # yoo2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// A standalone comment
|
// A standalone comment
|
||||||
|
|
||||||
aligned = {
|
aligned {
|
||||||
# Standalone 1
|
# Standalone 1
|
||||||
|
|
||||||
a = "bar" # yoo1
|
a = "bar" # yoo1
|
||||||
|
7
hcl/printer/testdata/complexhcl.golden
vendored
7
hcl/printer/testdata/complexhcl.golden
vendored
@ -26,10 +26,15 @@ resource aws_instance "web" {
|
|||||||
"${aws_security_group.firewall.foo}",
|
"${aws_security_group.firewall.foo}",
|
||||||
]
|
]
|
||||||
|
|
||||||
network_interface = {
|
network_interface {
|
||||||
device_index = 0
|
device_index = 0
|
||||||
description = "Main network interface"
|
description = "Main network interface"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network_interface = {
|
||||||
|
device_index = 1
|
||||||
|
description = "Another network interface"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "db" {
|
resource "aws_instance" "db" {
|
||||||
|
5
hcl/printer/testdata/complexhcl.input
vendored
5
hcl/printer/testdata/complexhcl.input
vendored
@ -29,6 +29,11 @@ resource "aws_security_group" "firewall" {
|
|||||||
device_index = 0
|
device_index = 0
|
||||||
description = "Main network interface"
|
description = "Main network interface"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network_interface = {
|
||||||
|
device_index = 1
|
||||||
|
description = "Another network interface"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_instance" "db" {
|
resource "aws_instance" "db" {
|
||||||
|
Loading…
Reference in New Issue
Block a user