Repository navigation
fix(fmt): keep the indent of one-line if/else chains - #3786
Merged
Merged
Conversation
…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.
|
Caution Review failedThe pull request is closed.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.