Skip to content

Expand single-line with initializers for IDE0055 - #381

Merged
thomhurst merged 3 commits into
mainfrom
fix/379-with-initializer-wrapping
Nov 20, 2026
Merged

thomhurst merged 3 commits into
mainfrom
fix/379-with-initializer-wrapping

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Curb expands with initializers that IDE0055 requires to span lines in preservation mode. The original repro now passes an IDE0055 build after Curb formats it.

Prompt summary

Investigate the formatter disagreement in #379, fix it, and add regression tests that check both expansion and preservation.

Why

Curb only forced breaks inside a with initializer when its braces already spanned lines. In the reported return statement, Roslyn allows those breaks once both single-line preservation settings are disabled.

What

Single-line wrapping

Curb checks whether a containing statement, declaration, or expression keeps the initializer on one line. It makes the expansion decision on the same pass when it opens an enclosing block.

Brace placement

Expanded initializers follow the initializer brace setting. An empty initializer can split its brace pair too.

Regression coverage

The tests cover populated and empty initializers, each preservation setting, an author-supplied break before the brace, and compact expression bodies. Each case checks that a second formatting pass gives the same result.

Corpus settings

The with fixtures select preservation explicitly. The generator carries that setting into their source snippets, including runs where the corpus sets a width.

Corpus measurements

Seed 1, 2,124 C# files. Each mode meets its conformance floor.

Layout SDK fixed points Files rewritten Net lines
No width 98.73% 2,121 +14,690
Corpus width 98.73% 2,122 +14,945
Width 120 98.68% 2,122 +23,979
Corpus width with explicit preservation 98.78% 2,121 +27,700

The default and 120-column runs report zero changes on the second pass. Second-pass counts in the preservation runs match the baseline.

Verify

dotnet run --project tests/Nullean.Curb.Tests -c Release -- --treenode-filter '/*/*/InitializerTests/*'
./build.sh verifyexpectations -s

Closes #379

Match IDE0055 wrapping when preservation mode allows a with initializer
to expand.

Refs #379
@thomhurst thomhurst added the bug A defect fixed (patch) label Nov 20, 2026
Carry preservation-mode fixture settings into the corpus so inherited
widths still exercise the wrapping rules under test.
@thomhurst
thomhurst merged commit b7b8f09 into main Nov 20, 2026
11 checks passed
@thomhurst
thomhurst deleted the fix/379-with-initializer-wrapping branch November 20, 2026 19:26
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.

Curb leaves single-line with initializers that IDE0055 expands

2 participants