Repository navigation
Refuse an empty #if condition and a multi-line directive argument [patch] - #155
Merged
matt-edmondson merged 1 commit intoNov 4, 2026
Merged
Conversation
…tch] DirectiveScope wrote its condition verbatim, so an empty, null or whitespace condition produced a bare "#if" (CS1517), and a condition with a line break left the rest of the expression outside the directive as code. PragmaScope had the same line-break problem with its warning list, including a single entry of the IEnumerable overload that kept a stray CR. Both now throw ArgumentException before writing anything, using the same LineTerminators check RegionScope got in #152. PragmaScope still treats empty or whitespace warnings as a no-op. Fixes #154 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2yWAiM4Xm9iHUvALj
|
matt-edmondson
deleted the
claude/issue-154-validate-directive-arguments
branch
November 4, 2026 00:53
matt-edmondson
pushed a commit
that referenced
this pull request
Nov 4, 2026
…ill refused PragmaScope.JoinWarnings trimmed every entry (#167), which stripped the terminator PragmaScopeRejectsWarningsThatSpanLinesBeforeWriting (#155) relies on, so main failed that test on every platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
matt-edmondson
added a commit
that referenced
this pull request
Nov 4, 2026
…e and out of the semicolon [patch] (#162) * Keep a preprocessor directive in an expression body off the arrow line 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 * Split the semicolon placement out of WriteExpressionBody 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 * Keep a pragma warning holding a line terminator untrimmed so it is still refused PragmaScope.JoinWarnings trimmed every entry (#167), which stripped the terminator PragmaScopeRejectsWarningsThatSpanLinesBeforeWriting (#155) relies on, so main failed that test on every platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1 --------- Co-authored-by: Claude <noreply@anthropic.com>
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 #154
What changed
DirectiveScopethrowsArgumentExceptionbefore writing anything when the condition is null, empty or whitespace. That case used to write a bare#if(CS1517). It also throws when the condition contains a line terminator.PragmaScopethrowsArgumentExceptionbefore writing anything when the warning list contains a line terminator. One check covers both constructors, because theIEnumerable<string>overload joins its entries first. Empty or whitespace warnings are still a no-op.LineTerminatorshelper thatRegionScopegot in Comment every line of a multi-line copyright, and refuse a multi-line region name [patch] #152 (LF, CRLF, CR, NEL, U+2028, U+2029).Tests
ScopesTests:DirectiveScopeRejectsAMissingConditionBeforeWriting(empty, whitespace, null),DirectiveScopeRejectsAConditionThatSpansLinesBeforeWritingandPragmaScopeRejectsWarningsThatSpanLinesBeforeWriting(each of the six terminators, bothPragmaScopeconstructors). Each one also asserts that nothing was written.Scopes.csreverted, all 15 new cases fail. With the fix, the full suite passes: 264 of 264 on net10.0, Linux, includingPragmaScopeWithAnEmptyStringIsANoOp.Note: releases are still blocked by #153 (pack fails package validation), so this won't reach NuGet until that is fixed.
Generated by Claude Code