Skip to content

Write a quoted empty default as "" instead of dropping it [patch] - #177

Merged
matt-edmondson merged 3 commits into
mainfrom
claude/issue-174-quoted-empty-default
Nov 4, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
claude/issue-174-quoted-empty-default

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #174

What changed

WriteDefaultValueTo and PropertyTemplate used to skip the initialiser whenever DefaultValue was empty. They did this even with DefaultValueIsQuoted set, where empty raw text means the empty string "". Both now go through one private protected HasDefaultValue => DefaultValueIsQuoted || !string.IsNullOrEmpty(DefaultValue), so the following now render correctly:

  • string separator = "" stays optional. Before, it became required, which gave CS1737 after an earlier optional parameter.
  • public const string Empty = ""; keeps its value. Before, the missing value gave CS0145.
  • Shorthand and braced properties keep = "";.

An empty default without quoting still writes no initialiser. The DefaultValue doc now explains the quoted case. The new member is private protected, so the public API does not change.

Tests

  • Added six tests to TemplateTests, covering a parameter, a method with a trailing optional parameter, a const field, a shorthand property and a braced property. They also confirm that an unquoted empty default still writes nothing.
  • With the fix reverted, five of the new tests fail. The unquoted guard test passes either way, as it should. With the fix, all 255 tests pass.
  • A local Sonar run (.sonarlint/sonar-local.props) reports only the five existing S2699 findings in the test project.

Generated by Claude Code

With DefaultValueIsQuoted set, empty raw text is the empty string, not
"no initialiser". WriteDefaultValueTo and PropertyTemplate now treat a
default as set when it is quoted or non-empty, so `string separator = ""`
stays optional and `const string Empty = ""` keeps its value.

Fixes #174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4VgeC1VNAtTYhxCrm
# Conflicts:
#	CodeBlocker/Templates/TemplateBase.cs

matt-edmondson commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

I merged main into this branch to clear the conflict in TemplateBase.cs. I kept main's new Validate() and this PR's HasDefaultValue cref.

Update: the red CI described below is now fixed on main. #162 changed JoinWarnings so that an entry containing a line terminator is no longer trimmed. Main has since been merged into this branch, and at e240d7f Test passes on ubuntu, windows and macos. The patch I proposed below is no longer needed.

Original note

Test on ubuntu/windows/macos each failed the same 6 PragmaScope line-terminator tests that also failed on main at 589a81a. The cause was #167: JoinWarnings trimmed each entry before Begin checked for line terminators, so a trailing terminator was removed before it could be refused.


Generated by Claude Code

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

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit aa59dae into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the claude/issue-174-quoted-empty-default branch November 4, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants