csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

fix: Null coalescing not own its line with complex left-hand side

Open ogaken-1 opened this issue 1 month ago • 2 comments

There was an issue where if the left-hand side of ?? was even slightly complex, the right-hand side would become part of the group and could not have its own line.

I reconsidered the conditions for grouping and changed it from judging the complexity of the left-hand side by a threshold to a condition where "the left-hand side is an InvocationExpression and consists solely of MemberAccessExpression that does not include an InvocationExpression".

fix #1769

ogaken-1 avatar Dec 07 '25 21:12 ogaken-1

Upon reviewing the PR that was created, I noticed there are some oversights. I'll work on the corrections later.

ogaken-1 avatar Dec 08 '25 06:12 ogaken-1

After reviewing the results in the csharpier-repos, I have added support for the following:

  • ParenthesizedExpressionSyntax
  • CastExpressionSyntax { Expression: ParenthesizedExpressionSyntax }
  • ConditionalAccessExpressionSyntax

ogaken-1 avatar Dec 08 '25 16:12 ogaken-1

@belav I made additional changes thinking they would be an improvement, but perhaps they weren't? I would be grateful for your opinion. Thank you.

ogaken-1 avatar Dec 12 '25 02:12 ogaken-1

Taking a look at the changes it made I think everythink looks good except this one - https://github.com/belav/csharpier-repos/pull/159/changes/e097ff1d5ab4cfc42a3ca55c92ceb38e3bfbd6c3#diff-bb147afabd02afcf48b4b4c09aad50f6bb117fea0bae21a1b2f1adef34f16beb

Your first pass had ?? false on a new line but the most recent version keeps it on the same line.

I don't see a test case for it which is probably why it ended up being undone.

Was there something specific you didn't think was an improvement? I do like the way it groups it with the ending paren

) ?? result

belav avatar Dec 12 '25 19:12 belav

Ideally I'd have an action for doing the formatting on csharpier-repos - I think I attempted it a while back and it wasn't super straightforward.

belav avatar Dec 12 '25 19:12 belav

Added support for when the leftmost element is a parenthesized expression.

ogaken-1 avatar Dec 13 '25 08:12 ogaken-1