mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.28k stars 346 forks source link

syntax: trailing white space added after opening parenthesis '(' #814

Closed ContinuousCaffeniation closed 2 years ago

ContinuousCaffeniation commented 2 years ago

In the second example below, a trailing blank/ white space is inserted after first opening '(' symbol, this is indicated through '^'. The expectation is like in first example above. This seems to happen when opening a subshell first after opening brackets of another subshell. shfmt is called without any parameters in this case.

#!/bin/bash

# OK - no blank
(
    cd .
    (echo "Hello world!")
)

# nok - blank ^ after first (
(^ 
    (echo "Hello world!")
)
mvdan commented 2 years ago

Thanks, this definitely sounds like a bug. We have logic to print two nested subshells in a single line as ( ( rather than ((, because the latter is ambiguous syntax. The logic is likely kicking in with multiple lines when it shouldn't be. Should be a relatively easy fix if anyone wants to take a look :)