Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
- make the if conditions more readable by adding parentheses separators
- reword comment on the double parens ambiguity
- make use of the `mustNewLine` variable to tell `stmtList` we must
  write a new line, instead of explicitly writing it up front
  • Loading branch information
riacataquian committed Jun 6, 2022
1 parent ee11534 commit 7848261
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions syntax/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,13 +1082,13 @@ func (p *Printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
stmts := x.Stmts
if len(stmts) > 0 && startsWithLparen(stmts[0]) {
p.wantSpace = spaceRequired
// we only want to keep the space between two nested subshells' open brackets
// if its in a single line to avoid ambiguity
if x.Lparen.Line() != stmts[0].Pos().Line() || len(stmts) > 1 && !p.singleLine {
// Add a space between nested parentheses if we're printing them in a single line,
// to avoid the ambiguity between `((` and `( (`.
if (x.Lparen.Line() != stmts[0].Pos().Line() || len(stmts) > 1) && !p.singleLine {
p.wantSpace = spaceNotRequired

if p.minify {
p.newline(stmts[0].Pos())
p.mustNewline = true
}
}
} else {
Expand Down Expand Up @@ -1349,7 +1349,7 @@ func (p *Printer) stmtList(stmts []*Stmt, last []Comment) {
// statement.
p.comments(c)
}
if !p.minify || p.wantSpace == spaceRequired {
if p.mustNewline || !p.minify || p.wantSpace == spaceRequired {
p.newlines(pos)
}
p.line = pos.Line()
Expand Down

0 comments on commit 7848261

Please sign in to comment.