printer: complex.golden is now fixed
This commit is contained in:
parent
66daded6ac
commit
858f6116bf
@ -33,6 +33,8 @@ func (b ByPosition) Len() int { return len(b) }
|
|||||||
func (b ByPosition) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
func (b ByPosition) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
func (b ByPosition) Less(i, j int) bool { return b[i].Pos().Before(b[j].Pos()) }
|
func (b ByPosition) Less(i, j int) bool { return b[i].Pos().Before(b[j].Pos()) }
|
||||||
|
|
||||||
|
// collectComments comments all standalone comments which are not lead or line
|
||||||
|
// comment
|
||||||
func (p *printer) collectComments(node ast.Node) {
|
func (p *printer) collectComments(node ast.Node) {
|
||||||
// first collect all comments. This is already stored in
|
// first collect all comments. This is already stored in
|
||||||
// ast.File.(comments)
|
// ast.File.(comments)
|
||||||
@ -83,25 +85,21 @@ func (p *printer) collectComments(node ast.Node) {
|
|||||||
sort.Sort(ByPosition(p.standaloneComments))
|
sort.Sort(ByPosition(p.standaloneComments))
|
||||||
}
|
}
|
||||||
|
|
||||||
var count int
|
|
||||||
|
|
||||||
// output prints creates b printable HCL output and returns it.
|
// output prints creates b printable HCL output and returns it.
|
||||||
func (p *printer) output(n interface{}) []byte {
|
func (p *printer) output(n interface{}) []byte {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
count++
|
|
||||||
|
|
||||||
switch t := n.(type) {
|
switch t := n.(type) {
|
||||||
case *ast.File:
|
case *ast.File:
|
||||||
return p.output(t.Node)
|
return p.output(t.Node)
|
||||||
case *ast.ObjectList:
|
case *ast.ObjectList:
|
||||||
|
|
||||||
var index int
|
var index int
|
||||||
var nextItem token.Pos
|
var nextItem token.Pos
|
||||||
var commented bool
|
var commented bool
|
||||||
for {
|
for {
|
||||||
// TODO(arslan): refactor below comment printing, we have the same in objectType
|
// TODO(arslan): refactor below comment printing, we have the same in objectType
|
||||||
|
|
||||||
// print stand alone upper level stand alone comments
|
// print upper leve stand alone comments
|
||||||
for _, c := range p.standaloneComments {
|
for _, c := range p.standaloneComments {
|
||||||
for _, comment := range c.List {
|
for _, comment := range c.List {
|
||||||
if index != len(t.Items) {
|
if index != len(t.Items) {
|
||||||
|
1
printer/testdata/complexhcl.golden
vendored
1
printer/testdata/complexhcl.golden
vendored
@ -35,6 +35,7 @@ resource aws_instance "web" {
|
|||||||
resource "aws_instance" "db" {
|
resource "aws_instance" "db" {
|
||||||
security_groups = "${aws_security_group.firewall.*.id}"
|
security_groups = "${aws_security_group.firewall.*.id}"
|
||||||
VPC = "foo"
|
VPC = "foo"
|
||||||
|
|
||||||
depends_on = ["aws_instance.web"]
|
depends_on = ["aws_instance.web"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
printer/testdata/complexhcl.input
vendored
3
printer/testdata/complexhcl.input
vendored
@ -36,9 +36,6 @@ resource "aws_instance" "db" {
|
|||||||
VPC = "foo"
|
VPC = "foo"
|
||||||
|
|
||||||
depends_on = ["aws_instance.web"]
|
depends_on = ["aws_instance.web"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output "web_ip" {
|
output "web_ip" {
|
||||||
|
Loading…
Reference in New Issue
Block a user