feat: add builderConstructorMandatoryParameters option to enforce man… - #119
Merged
Conversation
…datory constructor parameters in generated builders
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new builderConstructorMandatoryParameters configuration option to Buildenator, allowing generated builders to require the entity’s primary constructor parameters via a parameterized builder constructor, with supporting docs, diagnostics, and integration tests.
Changes:
- Introduces
builderConstructorMandatoryParametersin configuration/attributes and propagates it through generator configuration. - Updates constructor generation and suppresses the static factory property when mandatory parameters are enabled; adds BDN007 for mandatory+mocking incompatibility.
- Adds integration test coverage plus README/CHANGELOG documentation for the new option.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Buildenator.IntegrationTests/BuildersGeneratorMandatoryParametersTests.cs | Adds integration tests asserting mandatory builder ctor args, override behavior via With..., collections, and suppression of static factory property. |
| Tests/Buildenator.IntegrationTests/Buildenator.IntegrationTests.csproj | References the SourceWithoutAssemblyInfo project to compile/run the new scenario. |
| Tests/Buildenator.IntegrationTests.SourceWithoutAssemblyInfo/EntityWithMandatoryConstructorParametersBuilder.cs | Defines a builder annotated with builderConstructorMandatoryParameters: true for integration testing. |
| Tests/Buildenator.IntegrationTests.SharedEntities/EntityWithMandatoryConstructorParameters.cs | Adds an entity with a required constructor for the new feature scenario. |
| README.md | Documents the new option, its behavior, and provides an advanced usage example. |
| CHANGELOG.md | Adds a release note entry for builderConstructorMandatoryParameters and BDN007. |
| Buildenator/MakeBuilderAttributeInternal.cs | Extends internal attribute model to carry BuilderConstructorMandatoryParameters. |
| Buildenator/Generators/ConstructorsGenerator.cs | Implements generation of parameterized builder constructors when the option is enabled. |
| Buildenator/Generators/BuilderSourceStringGenerator.cs | Wires the option into constructor generation, suppresses static factory property, and emits BDN007 when combined with mocking configuration. |
| Buildenator/Diagnostics/BuildenatorDiagnosticDescriptors.cs | Adds diagnostic descriptor BDN007. |
| Buildenator/Configuration/Contract/IBuilderProperties.cs | Adds BuilderConstructorMandatoryParameters to builder configuration contract. |
| Buildenator/Configuration/BuilderProperties.cs | Propagates the new option through global/local configuration and exposes it via IBuilderProperties. |
| Buildenator/AnalyzerReleases.Unshipped.md | Registers BDN007 as a new shipped/unshipped analyzer diagnostic. |
| Buildenator.Abstraction/MakeBuilderAttribute.cs | Extends public attribute API with builderConstructorMandatoryParameters. |
| Buildenator.Abstraction/BuildenatorConfigurationAttribute.cs | Extends global configuration attribute API with builderConstructorMandatoryParameters. |
| } | ||
|
|
||
| var settableProperties = entity.AllUniqueSettablePropertiesAndParameters | ||
| .Where(p => constructorToBuild?.ContainsParameter(p.SymbolName) != true) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
…andatory constructor parameters fix: update changelog and README for new diagnostic errors BDN007 and BDN008 refactor: modify EntityWithMandatoryConstructorParameters to include tags and update related tests
…andatoryParameters in generated constructors
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.
…datory constructor parameters in generated builders