sh icon indicating copy to clipboard operation
sh copied to clipboard

Unnecessary line continuations are added to multi-line arithmetic expressions

Open jansorg opened this issue 5 months ago • 1 comments

shfmt 3.11.0 inserts unnecessary line continuations into multi-line arithmetic expressions. As far as I understand, line breaks are okay in arithmetic expressions and the line continuations could be skipped entirely.

((
 a > 2
 &&
 a < 10
)) && echo in range

is formatted like this:

((\
a > 2 && \
a < 10)) &&
        echo in range

but could be formatted similar to this:

((
a > 2 &&
a < 10)) &&
        echo in range

I'm unsure if there should be indentation inside a multiline ((...))).

jansorg avatar Jun 25 '25 14:06 jansorg

Thanks for spotting. We had just one test to cover the parsing of newlines in arithmetic expressions, which is surprising. But as you might have guessed, absolutely no tests in terms of how they are printed.

mvdan avatar Sep 13 '25 14:09 mvdan