mvdan/sh

Formatting suggestion: if-blocks with multiple conditions

mikez opened this issue · 2 comments

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.)