Fix double space between catch/where in where-only catch clause#1203
Merged
Conversation
When a `catch` clause's item consists solely of a `where` clause with no preceding pattern, the `CatchClauseSyntax` visitor inserts a space before the `catch` item's first token. With no pattern present, the first token is the `where` keyword. The `WhereClauseSyntax` visitor also inserts a preceding break before the same `where` keyword, producing duplicate whitespace. Suppress the `catch`-clause-level whitespace when a `catch` item has no pattern and allow `WhereClauseSyntax` to remain the sole source.
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.
Closes #1076.
When formatting a
catchclause whose item consists solely of awhereclause with no preceding pattern,TokenStreamCreator.visit(_ node: CatchClauseSyntax)emits a.spacebefore thecatchitem's first token. With no pattern present, the first token is thewherekeyword.TokenStreamCreator.visit(_ node: WhereClauseSyntax)also inserts a preceding break before the samewherekeyword, producing duplicate whitespace.This PR suppresses the
catch-clause-level whitespace when acatchitem has no pattern and allowsWhereClauseSyntaxto remain the sole source.Testing
Added
testCatchWhereOnly_noBreakBeforeCatch()andtestCatchWhereOnly_breakBeforeCatch()toDoStmtTests.All tests pass when run locally on macOS.