diff --git a/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs b/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs index 0ebc54df4a..c6d8670dcb 100644 --- a/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs +++ b/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs @@ -46,9 +46,9 @@ namespace Microsoft.AspNetCore.Components.Analyzers var type = (INamedTypeSymbol)context.Symbol; foreach (var member in type.GetMembers()) { - if (member is IPropertySymbol property && ComponentFacts.IsAnyParameter(symbols, property)) + if (member is IPropertySymbol property && ComponentFacts.IsParameter(symbols, property)) { - // Annotated with [Parameter] or [CascadingParameter] + // Annotated with [Parameter]. We ignore [CascadingParameter]'s because they don't interact with tooling and don't currently have any analyzer restrictions. properties.Add(property); } } diff --git a/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs b/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs index d58d1cfd14..88b366fd74 100644 --- a/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs +++ b/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs @@ -10,6 +10,22 @@ namespace Microsoft.AspNetCore.Components.Analyzers { public class ComponentParameterSettersShouldBePublicTest : DiagnosticVerifier { + [Fact] + public void IgnoresCascadingParameterProperties() + { + var test = $@" + namespace ConsoleApplication1 + {{ + using {typeof(CascadingParameterAttribute).Namespace}; + class TypeName + {{ + [CascadingParameter] string MyProperty {{ get; set; }} + }} + }}" + ComponentsTestDeclarations.Source; + + VerifyCSharpDiagnostic(test); + } + [Fact] public void IgnoresPublicSettersProperties() { diff --git a/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs b/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs index 4cf55844aa..69a3f2e310 100644 --- a/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs +++ b/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs @@ -37,7 +37,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Test class TypeName { [Parameter] private string BadProperty1 { get; set; } - [CascadingParameter] private object BadProperty2 { get; set; } } }" + ComponentsTestDeclarations.Source; @@ -51,16 +50,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Test { new DiagnosticResultLocation("Test0.cs", 8, 40) } - }, - new DiagnosticResult - { - Id = DiagnosticDescriptors.ComponentParametersShouldBePublic.Id, - Message = "Component parameter 'ConsoleApplication1.TypeName.BadProperty2' should be public.", - Severity = DiagnosticSeverity.Warning, - Locations = new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 49) - } }); VerifyCSharpFix(test, @" @@ -71,7 +60,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Test class TypeName { [Parameter] public string BadProperty1 { get; set; } - [CascadingParameter] public object BadProperty2 { get; set; } } }" + ComponentsTestDeclarations.Source); }