Repository navigation
Keep a preprocessor directive in an expression body off the arrow line and out of the semicolon [patch] - #162
Open
matt-edmondson wants to merge 2 commits into
Open
matt-edmondson wants to merge 2 commits into
matt-edmondson wants to merge 2 commits into
Conversation
…e and out of the semicolon [patch] WriteExpressionBody wrote the first content line straight after " => ", even a directive (CS1040), and appended the semicolon to the last line with code, which could be #endif (CS1025). A body that opens with a directive now starts on the line after the arrow, and when a directive follows the last line of code the semicolon goes on its own line after it, so every #if branch reaches it. Covers PropertyTemplate ExpressionBodyFactory and AccessorKind.Expression. Fixes #158 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3C2EQ5hMiLw63t4Aa
SonarCloud S3776 flagged the method's cognitive complexity (19 > 15) after the directive handling. The choice of which line takes the semicolon moves to FindTerminatedLine, and the code/directive checks become private helpers; behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3C2EQ5hMiLw63t4Aa
|
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.



Fixes #158
What changed
TemplateRendering.WriteExpressionBody, whichPropertyTemplate.ExpressionBodyFactoryandAccessorKind.Expressionshare, now handles preprocessor directives:=>and the directive starts the next line, which avoids CS1040.#if, so terminating it would leave the other branches unterminated. When any directive follows that line, the;goes on a line of its own after the last directive, where every branch reaches it. This avoids#endif;(CS1025) and leaves no branch without a terminator.public int P => x // note;does not compile (CS1002) #144 introduced.The repro now renders:
The issue's example form, with the
;inside each branch, was one option it offered. A trailing;after the directives is correct whether the branches are complete expressions or fragments of one, such as1#if DEBUG+ 2#endif. Terminating inside each branch would break that second case.Tests
ExpressionBodyFactoryand throughAccessorKind.Expression, plus an expression that ends in a conditional after code on the arrow line.;.Generated by Claude Code