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
6.97k stars 332 forks source link

Formatting suggestion: if-blocks with multiple conditions #1068

Open mikez opened 3 months ago

mikez commented 3 months ago

Hi @mvdan, I have a formatting suggestion involving if-blocks.

Instead of doing this:

a='aaa'
b='bbb'
c='ccc'
if [[ 
    $a == 'aaa' &&
    $b == 'bbb' &&
    $c == 'ccc' ]] \
    ; then
    echo yes
    # ...
fi

reformat like this:

a='aaa'
b='bbb'
c='ccc'
if [[
    $a == 'aaa'
    && $b == 'bbb'
    && $c == 'ccc'
]]; then
    echo yes
    # ...
fi

The formatting is inspired by what Python does with the black formatter. I think it makes the code more readable. (For operator placement, see also here.)