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

Formatting suggestion: if-blocks with multiple conditions #1068

Open
mikez opened this issue Mar 31, 2024 · 2 comments
Open

Formatting suggestion: if-blocks with multiple conditions #1068

mikez opened this issue Mar 31, 2024 · 2 comments

Comments

@mikez
Copy link

mikez commented Mar 31, 2024

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

@ColemanTom
Copy link

I would tend to agree, but recognise others may not. It makes diffs better if you add a new condition, its just a new line being added, rather than a new line being added and the ccc line being changed to shift the closing brackets.

The placement of || or && I think should be governed by the --binary-next-line option perhaps, although that negates my comment about which lines change in a diff.

@mikez
Copy link
Author

mikez commented Sep 6, 2024

@pschmitt it seems you're confused. Want to elaborate? :)

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

No branches or pull requests

2 participants