Repository navigation
fix: always put a space or newline after an added open brace - #841
Merged
Merged
Conversation
A body with braces gets a space after the open brace from one condition and a
newline after it from another. After the printer went back to an earlier point,
the newline could be resolved from where the statements ended before, so neither
was printed (ex. `} else {try {`), which then also made the open brace and the
arguments around it keep flipping until the re-evaluation limit was hit.
The newline is now used when there are braces, the body has content, and there's
no space after the open brace.
The corpus test now allows 20 formats to stop changing, since one file takes 13
formats with this.
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.
A body with braces gets the space after the open brace from one condition (
spaceCondition) and the newline after it from another (newLineCondition). After the printer went back to an earlier point, the newline could be resolved from where the statements ended before, so neither was printed:In some files this also made
openBraceand theisMultiLineForMultiLineof the arguments around it keep flipping until the re-evaluation limit was hit (ex. protobuf.js'sprotobuf.min.js), so the output was whatever they stopped at.The newline is now used when there are braces, the body has content, and there's no space after the open brace. The space is resolved earlier in the same pass, so the two can't disagree.
Changes in output
On the deno corpus, this changes the output of 174 files. The ones I looked at went from the above to a newline after the open brace (ex.
} else {try {in a web platform test and} else {resolutionCache == nullin TypeScript'stypescript.js). The files that change when formatted again went from 330 to 317, and no file hits the re-evaluation limit any more.One file (prettier's
parser-flow.mjs) now takes 13 formats to stop changing instead of fewer than 10, so the corpus test now allows 20.