Split chained using statements unless the option is written out - #91
Merged
Merged
Conversation
`using (a) using (b) { }` is a sequence, not a nesting: both usings guard the same
block and neither is the body of the other. The printer joined the chain onto one
line unconditionally, so `csharp_preserve_single_line_statements = false` was
ignored, which is what issue #89 reports.
Resolving the option would fix that much and leave the larger half wrong. It
defaults to true, so a repository with no .editorconfig -- or one that never
mentions this key -- would go on having its usings pulled onto one line. That is a
rewrite nobody asked for, and it is not the shape IDE0055 expects.
So the rule keys off whether the option was written out at all, not off its
resolved value:
absent split, one using per line
= false split
= true honour the author's own line breaks
`PreserveSingleLineStatementsOption` carries the raw setting and
`PreserveSingleLineStatements` resolves it, mirroring the existing
`KeepExistingLinebreaksOption` pair. Only the chained-using rule reads the raw
option; every other behaviour the option governs reads the resolved value and so
still defaults to preservation.
Verified in both directions: restoring the unconditional join fails the three
default-behaviour tests, and an unconditional split fails the opted-in test.
Confirmed end to end through `curb format` on a fixture with and without the key.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XK7BnefBydVSaXsrHEavmr
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 #89.
using (a) using (b) { }is a sequence, not a nesting: both usings guard the same block and neither is the body of the other. The printer joined the chain onto one line unconditionally, socsharp_preserve_single_line_statements = falsewas ignored — the bug #89 reports.Resolving the option would fix that much and leave the larger half wrong. It defaults to
true, so a repository with no.editorconfig, or one that never mentions this key, would go on having its usings pulled onto one line. That is a rewrite nobody asked for, and it is not the shape IDE0055 expects.The rule therefore keys off whether the option was written out at all, rather than off its resolved value:
csharp_preserve_single_line_statementsfalsetrueHow
PreserveSingleLineStatementsOptioncarries the raw setting andPreserveSingleLineStatementsresolves it, mirroring the existingKeepExistingLinebreaksOptionpair. Only the chained-using rule reads the raw option. Every other behaviour the option governs — a body on its header's line, acatchafter a brace, two statements sharing a semicolon, a statement on itscaselabel — reads the resolved value and still defaults to preservation.Verification
1,210 tests pass. The new cases were checked in both directions rather than only asserted:
Confirmed end to end through
curb formaton a fixture pair, where the plain directory reports 1 changed and the opted-in directory reports 0 changed.🤖 Generated with Claude Code
https://claude.ai/code/session_01XK7BnefBydVSaXsrHEavmr