Update of HCL Format dep

#Fixes 6346
This commit is contained in:
Justin Nauman 2016-04-26 06:35:46 -05:00
parent e3c3341a20
commit 6aba504b85
3 changed files with 31 additions and 13 deletions

22
Godeps/Godeps.json generated
View File

@ -720,47 +720,47 @@
},
{
"ImportPath": "github.com/hashicorp/hcl",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/ast",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/fmtcmd",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/parser",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/printer",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/scanner",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/strconv",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/hcl/token",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/json/parser",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/json/scanner",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hcl/json/token",
"Rev": "2604f3bda7e8960c1be1063709e7d7f0765048d0"
"Rev": "27a57f2605e04995c111273c263d51cee60d9bc4"
},
{
"ImportPath": "github.com/hashicorp/hil",

View File

@ -221,12 +221,12 @@ func (p *printer) objectType(o *ast.ObjectType) []byte {
defer un(trace(p, "ObjectType"))
var buf bytes.Buffer
buf.WriteString("{")
buf.WriteByte(newline)
var index int
var nextItem token.Pos
var commented bool
var commented, newlinePrinted bool
for {
// Print stand alone comments
for _, c := range p.standaloneComments {
for _, comment := range c.List {
@ -238,6 +238,13 @@ func (p *printer) objectType(o *ast.ObjectType) []byte {
}
if comment.Pos().After(p.prev) && comment.Pos().Before(nextItem) {
// If there are standalone comments and the initial newline has not
// been printed yet, do it now.
if !newlinePrinted {
newlinePrinted = true
buf.WriteByte(newline)
}
// add newline if it's between other printed nodes
if index > 0 {
commented = true
@ -258,6 +265,14 @@ func (p *printer) objectType(o *ast.ObjectType) []byte {
break
}
// At this point we are sure that it's not a totally empty block: print
// the initial newline if it hasn't been printed yet by the previous
// block about standalone comments.
if !newlinePrinted {
buf.WriteByte(newline)
newlinePrinted = true
}
// check if we have adjacent one liner items. If yes we'll going to align
// the comments.
var aligned []*ast.ObjectItem

View File

@ -60,5 +60,8 @@ func Format(src []byte) ([]byte, error) {
return nil, err
}
// Add trailing newline to result
buf.WriteString("\n")
return buf.Bytes(), nil
}