Skip to content

fix(fmt): keep the indent of one-line if/else chains - #3786

Merged
BaseMax merged 3 commits into
mainfrom
fix/fmt-if-chain
Nov 21, 2026
Merged

BaseMax merged 3 commits into
mainfrom
fix/fmt-if-chain

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 21, 2026

Copy link
Copy Markdown
Member

In a chain like 'if c == 1: add(r, 1)' followed by 'else c == 2: add(r, 2)', a call with two arguments after the colon was read as a tuple type annotation, so the block never opened and every else lost an indent level (the rest of the function landed at column 0).

Also 'else:println "small" end' on one source line was not idempotent: the second pass moved 'end' to its own line. Blocks whose body is forced onto a new line (else:, try/catch heads) now always put the closing word on its own line on the first pass.

Tested with a stage-1 build: tests/en/fmt all 20 pass, including the new if_chain (golden plus the runner's second-pass idempotency check). Formatting std/encoding json/toml/yaml value_bridge, toml and yaml files leaves them unchanged.

…odies idempotent

A call with two arguments after the colon was read as a tuple type annotation, so the block never opened. An else: block closed on the same source line is now split the same way on the first pass.
@BaseMax
BaseMax requested a review from a team as a code owner November 21, 2026 18:20
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BaseMax
BaseMax merged commit 2e36b23 into main Nov 21, 2026
14 of 15 checks passed
@BaseMax
BaseMax deleted the fix/fmt-if-chain branch November 21, 2026 18:22
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.

1 participant