Skip to content

syntax: apply BinaryNextLine to test and arithmetic expressions#1332

Open
kimjune01 wants to merge 1 commit into
mvdan:masterfrom
kimjune01:fix-813-binary-nextline
Open

syntax: apply BinaryNextLine to test and arithmetic expressions#1332
kimjune01 wants to merge 1 commit into
mvdan:masterfrom
kimjune01:fix-813-binary-nextline

Conversation

@kimjune01
Copy link
Copy Markdown

Fixes #813.

The -bn flag moves binary operators to the start of the next line for pipes and logical operators in commands, but didn't apply to [[ ]] test expressions or $(( )) arithmetic expressions. This meant shfmt -bn would reformat operators back to the end of the line in those contexts.

Handle BinaryTest (&&, ||) and BinaryArithm (+, etc.) the same way BinaryCmd already works: when the operand spans multiple lines, move the operator to the beginning of the continuation line with proper indentation.

Test cases cover single-line (unchanged), two-operand, three-operand chaining, and the exact example from the issue.

Fixes mvdan#813. The -bn flag now moves binary operators (&&, ||, +, etc.)
to the start of the next line for BinaryTest, AndTest, OrTest inside
[[ ]] and BinaryArithm inside $(( )), matching the existing BinaryCmd
behavior.
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

Successfully merging this pull request may close these issues.

syntax: make BinaryNextLine also apply to binary test and arithmetic expressions

1 participant