Skip to content

Skip blank entries in WriteUsings instead of writing using ; [patch] - #191

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/189-skip-blank-usings
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/189-skip-blank-usings

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #189

What changed

WriteUsings wrote every entry verbatim, so WriteUsings("System", "", "System.Linq") produced using ;, which fails with CS1001. SourceFileTemplate.Usings takes the same path. Null, empty and whitespace entries are now skipped, the same way #166 handles blank PragmaScope warnings. A list made only of blank entries writes nothing, not even the trailing blank line.

Not included

The issue also suggested refusing an entry that contains a line break. I left that out. AddSourceFile writes the documentation, comments and namespace before the usings, so throwing inside WriteUsings would leave partial output, which is what SourceFileTemplate's up-front validation exists to prevent. Doing it properly means adding a pre-write usings check to AddSourceFile, which can be its own change.

Tests

  • BlankUsingEntriesAreSkipped: "System", "", " ", null, "System.Linq" writes exactly the two real usings plus the blank line.
  • OnlyBlankUsingEntriesWriteNothingIncludingTheBlankLine: covers both overloads.
  • ASourceFileSkipsBlankUsings: covers the SourceFileTemplate.Usings path.

All three fail without the fix and pass with it. The full suite passes (332 tests).


Generated by Claude Code

WriteUsings wrote every entry verbatim, so an empty or whitespace entry
produced `using ;` (CS1001). A generator that builds optional usings as
`condition ? "Ns" : ""` hit this directly, as did SourceFileTemplate.Usings,
which goes through the same path. Null, empty and whitespace entries are now
skipped, and a list made only of them writes nothing, not even the trailing
blank line.

Fixes #189

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

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

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.

WriteUsings and SourceFileTemplate.Usings write using ; (CS1001) for an empty entry

2 participants