Skip to content

feat: add VOG038 analyzer for uninitialized Value Object properties#936

Merged
SteveDunn merged 7 commits into
mainfrom
feature/vog038-uninitialized-property-analyzer
May 10, 2026
Merged

feat: add VOG038 analyzer for uninitialized Value Object properties#936
SteveDunn merged 7 commits into
mainfrom
feature/vog038-uninitialized-property-analyzer

Conversation

@SteveDunn

Copy link
Copy Markdown
Owner

Implements the analyzer requested in issue #934.

Warns (VOG038) when a property whose type is a Vogen Value Object is non-nullable, lacks the 'required' modifier, and has no initializer. This pattern silently produces an invalid (uninitialized) Value Object whenever the containing type is constructed without setting the property

  • a common footgun with EF Core entities and other data-transfer types.

Acceptable patterns that suppress the diagnostic:

  • nullable property: public MyVo? Prop { get; set; }
  • required property: public required MyVo Prop { get; set; }
  • initializer: public MyVo Prop { get; set; } = MyVo.From(0);
  • getter-only property: public MyVo Prop { get; } (compiler enforces init)

Changes:

  • src/Vogen/Diagnostics/RuleIdentifiers.cs: add VOG038 constant
  • src/Vogen/Rules/DoNotUseUninitializedValueObjectInPropertyAnalyzer.cs: new analyzer
  • src/Vogen/AnalyzerReleases.Unshipped.md: register VOG038
  • tests/AnalyzerTests/DoNotUseUninitializedValueObjectInPropertyTests.cs: test coverage

Implements the analyzer requested in issue #934.

Warns (VOG038) when a property whose type is a Vogen Value Object
is non-nullable, lacks the 'required' modifier, and has no initializer.
This pattern silently produces an invalid (uninitialized) Value Object
whenever the containing type is constructed without setting the property
- a common footgun with EF Core entities and other data-transfer types.

Acceptable patterns that suppress the diagnostic:
  - nullable property:    public MyVo? Prop { get; set; }
  - required property:    public required MyVo Prop { get; set; }
  - initializer:          public MyVo Prop { get; set; } = MyVo.From(0);
  - getter-only property: public MyVo Prop { get; }  (compiler enforces init)

Changes:
  - src/Vogen/Diagnostics/RuleIdentifiers.cs: add VOG038 constant
  - src/Vogen/Rules/DoNotUseUninitializedValueObjectInPropertyAnalyzer.cs: new analyzer
  - src/Vogen/AnalyzerReleases.Unshipped.md: register VOG038
  - tests/AnalyzerTests/DoNotUseUninitializedValueObjectInPropertyTests.cs: test coverage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JoschiZ

JoschiZ commented May 8, 2026

Copy link
Copy Markdown
Contributor

I actually already wrote a fully working implementation for my own use, that I may be allowed to give you.

It handles:

  • Properties
  • Fields
  • Assignment in the Constructor chain
  • Manual auto property assignments to the backing field

@SteveDunn

Copy link
Copy Markdown
Owner Author

That'd be great if you could do a PR. Copilot did one for me but I haven't check it.

@JoschiZ

JoschiZ commented May 8, 2026

Copy link
Copy Markdown
Contributor

Will do

@JoschkaBC JoschkaBC mentioned this pull request May 8, 2026
@SteveDunn
SteveDunn merged commit 1647f56 into main May 10, 2026
6 checks passed
@SteveDunn
SteveDunn deleted the feature/vog038-uninitialized-property-analyzer branch May 10, 2026 16:07
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.

2 participants