diff --git a/src/Components/Analyzers/src/DiagnosticDescriptors.cs b/src/Components/Analyzers/src/DiagnosticDescriptors.cs index 5f67edaf8447..da32af48db18 100644 --- a/src/Components/Analyzers/src/DiagnosticDescriptors.cs +++ b/src/Components/Analyzers/src/DiagnosticDescriptors.cs @@ -73,7 +73,8 @@ internal static class DiagnosticDescriptors CreateLocalizableResourceString(nameof(Resources.ComponentParametersShouldBeAutoProperties_Message)), Usage, DiagnosticSeverity.Warning, - isEnabledByDefault: true); + isEnabledByDefault: true, + description: CreateLocalizableResourceString(nameof(Resources.ComponentParametersShouldBeAutoProperties_Description))); public static readonly DiagnosticDescriptor SupplyParameterFromFormShouldNotHavePropertyInitializer = new( "BL0008", diff --git a/src/Components/Analyzers/src/Resources.resx b/src/Components/Analyzers/src/Resources.resx index 6a23211094aa..5e9e77d7e07f 100644 --- a/src/Components/Analyzers/src/Resources.resx +++ b/src/Components/Analyzers/src/Resources.resx @@ -175,11 +175,14 @@ Do not use RenderTree types - Component parameter '{0}' should be auto property + Component parameter '{0}' should be auto property. Manipulating component parameters can result in infinite loops and unintended side effects. Component parameters should be auto properties + + Component parameters should be auto properties. Manipulating component parameters can result in infinite loops and unintended side effects. Use @bind:after or @bind:set instead to adjust values or trigger additional callbacks. + The value of a property decorated with [SupplyParameterFromForm] and initialized with a property initializer can be overwritten with null when the component receives parameters. To ensure the initialized value is not overwritten, move the initialization to a component lifecycle method like OnInitialized or OnInitializedAsync diff --git a/src/Components/Analyzers/test/ComponentParameterShouldBeAutoPropertiesTest.cs b/src/Components/Analyzers/test/ComponentParameterShouldBeAutoPropertiesTest.cs index 71826a256f30..2c98b363c262 100644 --- a/src/Components/Analyzers/test/ComponentParameterShouldBeAutoPropertiesTest.cs +++ b/src/Components/Analyzers/test/ComponentParameterShouldBeAutoPropertiesTest.cs @@ -100,7 +100,7 @@ private void DoSomething() { } VerifyCSharpDiagnostic(source, new DiagnosticResult { Id = DiagnosticDescriptors.ComponentParametersShouldBeAutoProperties.Id, - Message = "Component parameter 'C.MyProp' should be auto property", + Message = "Component parameter 'C.MyProp' should be auto property. Manipulating component parameters can result in infinite loops and unintended side effects.", Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 15), @@ -139,7 +139,7 @@ private void DoSomething() { } VerifyCSharpDiagnostic(source, new DiagnosticResult { Id = DiagnosticDescriptors.ComponentParametersShouldBeAutoProperties.Id, - Message = "Component parameter 'C.MyProp' should be auto property", + Message = "Component parameter 'C.MyProp' should be auto property. Manipulating component parameters can result in infinite loops and unintended side effects.", Locations = new[] { new DiagnosticResultLocation("Test0.cs", 9, 15),