feat: add VOG038 analyzer for uninitialized Value Object properties#936
Merged
Merged
Conversation
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>
Contributor
|
I actually already wrote a fully working implementation for my own use, that I may be allowed to give you. It handles:
|
Owner
Author
|
That'd be great if you could do a PR. Copilot did one for me but I haven't check it. |
Contributor
|
Will do |
…non-nullable Value Objects to ensure initialization
…for Value Object properties in tests
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Acceptable patterns that suppress the diagnostic:
Changes: