Repository navigation
Refuse an empty #if condition and a multi-line directive argument [patch] - #155
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
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
|
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