Skip to content

Place a property pattern's braces at the line dotnet format uses - #371

Merged
Mpdreamz merged 1 commit into
nullean:mainfrom
thomhurst:property-pattern-braces-in-lambda
Nov 16, 2026
Merged

Mpdreamz merged 1 commit into
nullean:mainfrom
thomhurst:property-pattern-braces-in-lambda

Conversation

@thomhurst

Copy link
Copy Markdown
Contributor

A property pattern's { on a line of its own now goes where dotnet format puts 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 {, Length and } lines, and running dotnet format over Curb's output gives a third layout. Curb placed the brace at the ambient indent, and an argument list or lambda adds a level that dotnet format does not.

What

The rule, from Roslyn

IndentBlockFormattingRule aligns a property pattern's braces to the first token on the line holding recursivePattern.Parent.GetFirstToken(): the is expression, the or chain, the switch arm or the case label. It also sets IndentIfConditionOfAnchorToken, which adds a level when that line is the line an if or while starts. An else if line starts with the else, so it gets no extra level. I checked each of these shapes against dotnet format whitespace --folder (SDK 11.0.100): lambdas in arguments and in a .Where chain, && on either side of the pattern, an embedded statement, is / string or string, switch arms in a lambda, if, else if, while with a lambda in its condition, and case labels.

Where Curb puts the brace

PropertyBraceOwnerLine claims a register for that line with OwnerLineAnchor, as the switch expression and initializers already do. RecursivePattern prints the brace, members and closing brace aligned to that register. The extra condition level is read with AuthorJoined. 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's GapBeforePattern, so the brace could not move with its members. BareRecursivePatternOwnsLeadingBrace now also gives RecursivePattern a bare pattern that follows is, not, and, or or a colon when the author broke before its brace and no chain comes after it. The break stays outside the pattern's group, so is / { 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 format puts that brace one level in from the ( line, and Curb joins it as ({. ParenthesizedPattern drops every break the author put inside a parenthesized pattern, which is the same on main. That is the parenthesized-pattern indent block that #206 handled for positional patterns, not this alignment rule.

Verify

dotnet run --project tests/Nullean.Curb.Tests -c Release -- --treenode-filter "/*/*/PatternTests/*"
# Property_pattern_braces_in_a_lambda_argument_stay_at_the_lambdas_line: the issue's input
# Property_pattern_braces_go_to_the_line_holding_what_holds_the_pattern: every owner, conditions, bare and empty braces
# Property_pattern_braces_in_a_broken_argument_sit_at_the_arguments_line: max_line_length = 50

Each expected output is a fixed point of dotnet format whitespace. With no width, Curb's output on every probe shape is byte-identical to dotnet format's, also with tabs and with csharp_indent_braces = true. Each part fails a test when reverted on its own: the condition level, the owner line, the bare-brace ownership and the else if exception. The full suite passes (2274, 2 skipped), ./build.sh verifyexpectations passes, and curb check src tools tests reports nothing to change.

Closes #367

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]>
@Mpdreamz Mpdreamz added the bug A defect fixed (patch) label Nov 16, 2026
@Mpdreamz
Mpdreamz merged commit ee07c13 into nullean:main Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A defect fixed (patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE0055 disagrees on a property pattern's braces in a lambda argument

2 participants