-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Options validation source generator #87587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
304dd3d
Options validation source generator
tarekgh b662e52
Add source gen to the package and clean up some resources
tarekgh f20f8e6
Change the initialization to use ForAttributeWithMetadataName
tarekgh 86409c0
Excluding tests on WASM
tarekgh 9456bf5
Address Martin's feedback
tarekgh f61cae6
Address Jeff's comments
tarekgh 8e6c7a0
Replace the calls of ValidationAttribute.GetValidationResult with Val…
tarekgh c18789c
Avoid calling List.Clean and create the list with initial capacity
tarekgh 8ea301d
Pass down the SematicModel from the generator to the parser
tarekgh 54a2f97
Add isolated unit test
tarekgh 9119332
Final fixes
tarekgh c98e5fc
Fix resource messages
tarekgh ec2c6e4
Address more feedback
tarekgh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
95 changes: 95 additions & 0 deletions
95
src/libraries/Microsoft.Extensions.Options/gen/DiagDescriptors.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.CodeAnalysis; | ||
| using System; | ||
|
|
||
| namespace Microsoft.Extensions.Options.Generators | ||
| { | ||
| internal sealed class DiagDescriptors : DiagDescriptorsBase | ||
| { | ||
| private const string Category = "Microsoft.Extensions.Options.SourceGeneration"; | ||
|
|
||
| public static DiagnosticDescriptor CantUseWithGenericTypes { get; } = Make( | ||
| id: "SYSLIB1201", | ||
| title: SR.CantUseWithGenericTypesTitle, | ||
| messageFormat: SR.CantUseWithGenericTypesMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor NoEligibleMember { get; } = Make( | ||
| id: "SYSLIB1202", | ||
| title: SR.NoEligibleMemberTitle, | ||
| messageFormat: SR.NoEligibleMemberMessage, | ||
| category: Category, | ||
| defaultSeverity: DiagnosticSeverity.Warning); | ||
|
|
||
| public static DiagnosticDescriptor NoEligibleMembersFromValidator { get; } = Make( | ||
| id: "SYSLIB1203", | ||
| title: SR.NoEligibleMembersFromValidatorTitle, | ||
| messageFormat: SR.NoEligibleMembersFromValidatorMessage, | ||
| category: Category, | ||
| defaultSeverity: DiagnosticSeverity.Warning); | ||
|
|
||
| public static DiagnosticDescriptor DoesntImplementIValidateOptions { get; } = Make( | ||
| id: "SYSLIB1204", | ||
| title: SR.DoesntImplementIValidateOptionsTitle, | ||
| messageFormat: SR.DoesntImplementIValidateOptionsMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor AlreadyImplementsValidateMethod { get; } = Make( | ||
| id: "SYSLIB1205", | ||
| title: SR.AlreadyImplementsValidateMethodTitle, | ||
| messageFormat: SR.AlreadyImplementsValidateMethodMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor MemberIsInaccessible { get; } = Make( | ||
| id: "SYSLIB1206", | ||
| title: SR.MemberIsInaccessibleTitle, | ||
| messageFormat: SR.MemberIsInaccessibleMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor NotEnumerableType { get; } = Make( | ||
| id: "SYSLIB1207", | ||
| title: SR.NotEnumerableTypeTitle, | ||
| messageFormat: SR.NotEnumerableTypeMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor ValidatorsNeedSimpleConstructor { get; } = Make( | ||
| id: "SYSLIB1208", | ||
| title: SR.ValidatorsNeedSimpleConstructorTitle, | ||
| messageFormat: SR.ValidatorsNeedSimpleConstructorMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor CantBeStaticClass { get; } = Make( | ||
| id: "SYSLIB1209", | ||
| title: SR.CantBeStaticClassTitle, | ||
| messageFormat: SR.CantBeStaticClassMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor NullValidatorType { get; } = Make( | ||
| id: "SYSLIB1210", | ||
| title: SR.NullValidatorTypeTitle, | ||
| messageFormat: SR.NullValidatorTypeMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor CircularTypeReferences { get; } = Make( | ||
| id: "SYSLIB1211", | ||
| title: SR.CircularTypeReferencesTitle, | ||
| messageFormat: SR.CircularTypeReferencesMessage, | ||
| category: Category); | ||
|
|
||
| public static DiagnosticDescriptor PotentiallyMissingTransitiveValidation { get; } = Make( | ||
| id: "SYSLIB1212", | ||
| title: SR.PotentiallyMissingTransitiveValidationTitle, | ||
| messageFormat: SR.PotentiallyMissingTransitiveValidationMessage, | ||
| category: Category, | ||
| defaultSeverity: DiagnosticSeverity.Warning); | ||
|
|
||
| public static DiagnosticDescriptor PotentiallyMissingEnumerableValidation { get; } = Make( | ||
| id: "SYSLIB1213", | ||
| title: SR.PotentiallyMissingEnumerableValidationTitle, | ||
| messageFormat: SR.PotentiallyMissingEnumerableValidationMessage, | ||
| category: Category, | ||
| defaultSeverity: DiagnosticSeverity.Warning); | ||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
src/libraries/Microsoft.Extensions.Options/gen/DiagDescriptorsBase.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Microsoft.CodeAnalysis; | ||
|
|
||
| namespace Microsoft.Extensions.Options.Generators | ||
| { | ||
| #pragma warning disable CA1052 // Static holder types should be Static or NotInheritable | ||
| internal class DiagDescriptorsBase | ||
| #pragma warning restore CA1052 | ||
| { | ||
| protected static DiagnosticDescriptor Make( | ||
| string id, | ||
| string title, | ||
| string messageFormat, | ||
| string category, | ||
| DiagnosticSeverity defaultSeverity = DiagnosticSeverity.Error, | ||
| bool isEnabledByDefault = true) | ||
| { | ||
| return new( | ||
| id, | ||
| title, | ||
| messageFormat, | ||
| category, | ||
| defaultSeverity, | ||
| isEnabledByDefault); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.