Skip to content

Commit

Permalink
Fixed bug where buildifier swallowed up some comments at the beginnin…
Browse files Browse the repository at this point in the history
…g of list/d

ictionary expressions.

Fixes bazelbuild#68 on github
  • Loading branch information
gcc42 committed Mar 22, 2017
1 parent 7d7b76a commit bcb27d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ func (in *input) assignComments() {
// whole file, or conditional expression.
// Instead assign them to the last argument, element, or rule.
switch x.(type) {
case *CallExpr, *ListExpr, *End, *File, *ConditionalExpr:
case *CallExpr, *ListExpr, *End, *File,
*ConditionalExpr, *IfClause, *ForClause:
continue
}

Expand Down
11 changes: 10 additions & 1 deletion build/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ func (p *printer) file(f *File) {
for i, stmt := range f.Stmt {
switch stmt := stmt.(type) {
case *CommentBlock:
// comments already handled
// This is necessary so that CommentBlock
// doesn't swallow up suffix comments of
// the expression after it.
for _, scom := range stmt.Suffix {
scom.Suffix = false
stmt.After = append(stmt.After, scom)
suffix := stmt.Suffix
stmt.Suffix = suffix[:len(suffix) - 1]
}


case *PythonBlock:
for _, com := range stmt.Before {
Expand Down

0 comments on commit bcb27d7

Please sign in to comment.