Skip to content

Skip empty entries in a PragmaScope warning list [patch] - #167

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/issue-166-pragma-empty-warning-entries
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/issue-166-pragma-empty-warning-entries

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #166

Summary

PragmaScope(CodeBlocker, IEnumerable<string>) joined its entries with ", " before the empty check in Begin/End ran. A list of empty strings therefore joined to ", " and wrote #pragma warning disable , (CS1072), and a mixed list like { "CS0168", "" } wrote a trailing comma.

The constructor now trims each entry and drops null, empty and whitespace ones before joining:

  • new PragmaScope(cb, ["", ""]) writes no directives.
  • new PragmaScope(cb, ["CS0168", ""]) writes #pragma warning disable CS0168, with no trailing comma.

The string constructor is unchanged.

Tests

  • PragmaScopeWithOnlyEmptyWarningEntriesIsANoOp and PragmaScopeSkipsEmptyWarningEntriesAmongRealOnes both fail on main and pass with the fix. I checked this by reverting Scopes.cs and running them again.
  • Full suite: 251/251 pass.

Generated by Claude Code

The IEnumerable<string> constructor joined its entries before the empty
check ran, so a list of empty strings joined to ", " and wrote
`#pragma warning disable , ` (CS1072). Entries are now trimmed and null,
empty or whitespace ones are dropped before joining, so such a list is a
no-op and a mixed list carries no trailing comma.

Fixes #166

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3PT52Zo3M7fFP8Z6J
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit a607dc7 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the claude/issue-166-pragma-empty-warning-entries branch November 4, 2026 00:54
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PragmaScope with a list of empty warning IDs writes #pragma warning disable , (CS1072) instead of nothing

2 participants