镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Write no namespace line for a whitespace-only namespace [patch] - #204

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/blank-namespace-203
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/blank-namespace-203

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #203

What was wrong

WriteFileScopedNamespace skipped only a null or empty namespace. SourceFileTemplate { Namespace = " " } wrote namespace ;, which fails with CS1001. Blank usings, attributes and list entries were already skipped with IsNullOrWhiteSpace (#189, #191, #200).

Change

  • CodeBlockerExtensions.WriteFileScopedNamespace now uses string.IsNullOrWhiteSpace, so a whitespace-only namespace writes nothing, the same as "".
  • The doc comments on WriteFileScopedNamespace and SourceFileTemplate.Namespace now say that whitespace counts as no namespace.

Tests

  • New: AWhitespaceNamespaceWritesNothing (" " and "\t" through the extension).
  • New: ASourceFileWithAWhitespaceNamespaceWritesNoNamespace. This is the issue's repro: Namespace = " " plus a blank using writes only using System;.
  • Both fail with the fix reverted. Full suite on Linux / .NET 10: 379/379 passed.

Generated by Claude Code

WriteFileScopedNamespace checked IsNullOrEmpty, so SourceFileTemplate.Namespace = " "
wrote 'namespace  ;' (CS1001). Blank usings, attributes and list entries are already
skipped with IsNullOrWhiteSpace; the namespace now matches.

Fixes #203

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

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.

A whitespace-only SourceFileTemplate.Namespace writes namespace ; (CS1001), though blank usings are skipped

2 participants