Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: fix whitespace on nested subshells #869

Merged
merged 5 commits into from
Jun 6, 2022

Conversation

riacataquian
Copy link
Collaborator

we want white space on nested subshells if its in a single line since
its ambiguous, eg we want ( ( over ((

this shouldn't be the case for multiple lines- fix the logic that adds
white space to only do so if the two subshells are in the same line

fixes #814

we want white space on nested subshells if its in a single line since
its ambiguous, eg we want `( (` over `((`

this shouldn't be the case for multiple lines- fix the logic that adds
white space to only do so if the two subshells are in the same line

fixes mvdan#814
@riacataquian riacataquian requested a review from mvdan May 31, 2022 11:40
Copy link
Owner

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts :)

syntax/printer.go Outdated Show resolved Hide resolved
syntax/printer.go Outdated Show resolved Hide resolved
the fix fall short for some scenarios such as when we actually want new
line, eg there's more than one statement; fix the logic to also not add
white space for such scenarios

also add more tests for the different types
syntax/printer_test.go Outdated Show resolved Hide resolved
on instances when command is a SubShell, `startsWithLparen` condition
is met and there's more than one statement, we want:
- space between the statements if `SingleLine` is enabled
- new line between the statements if `Minify` is enabled

otherwise we'd get `reached ) without matching (( with ))` syntax
errors; rightfully so, because of the root issue we've been trying to solve,
being `((` is ambiguous
Copy link
Owner

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests LGTM, thanks! Just some code nits.

syntax/printer.go Outdated Show resolved Hide resolved
syntax/printer.go Outdated Show resolved Hide resolved
syntax/printer.go Outdated Show resolved Hide resolved
- 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
@riacataquian riacataquian enabled auto-merge (rebase) June 6, 2022 13:11
@riacataquian riacataquian merged commit 7848261 into mvdan:master Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

syntax: trailing white space added after opening parenthesis '('
2 participants