Don't apply analyzer restrictions to cascading parameters.

- Today all of our analyzer warnings only operate on `[Parameter]` properties.
- Updated existing test to not expect `CascadingParameter` as a possible error case.
- Added a new test to ensure we skip `CascadingParameter`s.

#8825
This commit is contained in:
N. Taylor Mullen 2019-07-10 12:55:29 -07:00
parent 8fa4df9bda
commit a2e26434aa
3 changed files with 18 additions and 14 deletions

View File

@ -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);
}
}

View File

@ -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()
{

View File

@ -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);
}