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:
parent
8fa4df9bda
commit
a2e26434aa
|
|
@ -46,9 +46,9 @@ namespace Microsoft.AspNetCore.Components.Analyzers
|
||||||
var type = (INamedTypeSymbol)context.Symbol;
|
var type = (INamedTypeSymbol)context.Symbol;
|
||||||
foreach (var member in type.GetMembers())
|
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);
|
properties.Add(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,22 @@ namespace Microsoft.AspNetCore.Components.Analyzers
|
||||||
{
|
{
|
||||||
public class ComponentParameterSettersShouldBePublicTest : DiagnosticVerifier
|
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]
|
[Fact]
|
||||||
public void IgnoresPublicSettersProperties()
|
public void IgnoresPublicSettersProperties()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Test
|
||||||
class TypeName
|
class TypeName
|
||||||
{
|
{
|
||||||
[Parameter] private string BadProperty1 { get; set; }
|
[Parameter] private string BadProperty1 { get; set; }
|
||||||
[CascadingParameter] private object BadProperty2 { get; set; }
|
|
||||||
}
|
}
|
||||||
}" + ComponentsTestDeclarations.Source;
|
}" + ComponentsTestDeclarations.Source;
|
||||||
|
|
||||||
|
|
@ -51,16 +50,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Test
|
||||||
{
|
{
|
||||||
new DiagnosticResultLocation("Test0.cs", 8, 40)
|
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, @"
|
VerifyCSharpFix(test, @"
|
||||||
|
|
@ -71,7 +60,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Test
|
||||||
class TypeName
|
class TypeName
|
||||||
{
|
{
|
||||||
[Parameter] public string BadProperty1 { get; set; }
|
[Parameter] public string BadProperty1 { get; set; }
|
||||||
[CascadingParameter] public object BadProperty2 { get; set; }
|
|
||||||
}
|
}
|
||||||
}" + ComponentsTestDeclarations.Source);
|
}" + ComponentsTestDeclarations.Source);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue