Repository navigation
Place a property pattern's braces at the line dotnet format uses - #371
Merged
Mpdreamz merged 1 commit intoNov 16, 2026
Merged
Conversation
dotnet format aligns a property pattern's braces to the line holding the first token of what holds the pattern, plus a level on an if or while keyword's line. Curb used the ambient indent, so in a lambda argument or a call's argument the braces sat a level right, and IDE0055 moved them back. Co-Authored-By: Claude <[email protected]>
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 property pattern's
{on a line of its own now goes wheredotnet formatputs it: at the indent of the line holding the first token of whatever holds the pattern. In a lambda argument or a call's argument, Curb had put the braces and members a level to the right.Prompt summary: The author tried Curb on a codebase and filed the formatting differences they found against
dotnet format. They asked for this one to be fixed: #367, a property pattern's braces in a lambda argument.Why
With no width, #367's
.Where(item => item is string/{/Length: 1/} s && s != "x")comes out four columns to the right. IDE0055 then flags the{,Lengthand}lines, and runningdotnet formatover Curb's output gives a third layout. Curb placed the brace at the ambient indent, and an argument list or lambda adds a level thatdotnet formatdoes not.What
The rule, from Roslyn
IndentBlockFormattingRulealigns a property pattern's braces to the first token on the line holdingrecursivePattern.Parent.GetFirstToken(): theisexpression, theorchain, the switch arm or the case label. It also setsIndentIfConditionOfAnchorToken, which adds a level when that line is the line aniforwhilestarts. Anelse ifline starts with theelse, so it gets no extra level. I checked each of these shapes againstdotnet format whitespace --folder(SDK 11.0.100): lambdas in arguments and in a.Wherechain,&&on either side of the pattern, an embedded statement,is/string or string, switch arms in a lambda,if,else if,whilewith a lambda in its condition, and case labels.Where Curb puts the brace
PropertyBraceOwnerLineclaims a register for that line withOwnerLineAnchor, as the switch expression and initializers already do.RecursivePatternprints the brace, members and closing brace aligned to that register. The extra condition level is read withAuthorJoined. Deterministic layout never keeps a condition on its keyword's line once a brace inside it breaks, because the header's group breaks after the(first. When the brace would sit on the line it measures from, as with a pattern that starts what holds it, the brace keeps the ambient indent, which is what Roslyn does too.A bare brace the author broke
x is/{ … }used to get its line from the caller'sGapBeforePattern, so the brace could not move with its members.BareRecursivePatternOwnsLeadingBracenow also givesRecursivePatterna bare pattern that followsis,not,and,oror a colon when the author broke before its brace and no chain comes after it. The break stays outside the pattern's group, sois/{ A: 1 }is not opened out. A chain that starts with a brace still breaks to the brace column, as before.Out of scope:
return item is (/{ Length: 1 }).dotnet formatputs that brace one level in from the(line, and Curb joins it as({.ParenthesizedPatterndrops every break the author put inside a parenthesized pattern, which is the same onmain. That is the parenthesized-pattern indent block that #206 handled for positional patterns, not this alignment rule.Verify
Each expected output is a fixed point of
dotnet format whitespace. With no width, Curb's output on every probe shape is byte-identical todotnet format's, also with tabs and withcsharp_indent_braces = true. Each part fails a test when reverted on its own: the condition level, the owner line, the bare-brace ownership and theelse ifexception. The full suite passes (2274, 2 skipped),./build.sh verifyexpectationspasses, andcurb check src tools testsreports nothing to change.Closes #367