rspec/rules/S6803/csharp/rule.adoc
2024-04-24 13:37:29 +02:00

52 lines
1.6 KiB
Plaintext

*This rule is deprecated, and will eventually be removed.*
Component parameters can only receive query parameter values in routable components with an @page directive.
== Why is this an issue?
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.supplyparameterfromqueryattribute[SupplyParameterFromQuery] attribute is used to specify that a component parameter of a routable component comes from the https://en.wikipedia.org/wiki/Query_string[query string].
In the case of non-routable components, the `SupplyParameterFromQuery` does not contribute to the functionality, and removing it will not affect the behavior.
== How to fix it
Either make the component routable or remove the `SupplyParameterFromQuery` attribute.
=== Code examples
==== Noncompliant code example
[source,csharp,diff-id=1,diff-type=noncompliant]
----
<h3>Component</h3>
@code {
[Parameter]
[SupplyParameterFromQuery] // Noncompliant
public bool Param { get; set; }
}
----
==== Compliant solution
[source,csharp,diff-id=1,diff-type=compliant]
----
@page "/component"
<h3>Component</h3>
@code {
[Parameter]
[SupplyParameterFromQuery] // Compliant
public bool Param { get; set; }
}
----
== Resources
=== Documentation
* Microsoft Learn - https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing#query-strings[Query strings]
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.supplyparameterfromqueryattribute[SupplyParameterFromQueryAttribute Class]
* Wikipedia - https://en.wikipedia.org/wiki/Query_string[query string]