-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create rule S6803: Parameters with SupplyParameterFromQuery attribute…
… should be used only in routable components (#3216)
- Loading branch information
1 parent
da5a5e1
commit 68a958f
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"title": "Parameters with SupplyParameterFromQuery attribute should be used only in routable components", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"blazor" | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-6803", | ||
"sqKey": "S6803", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "infeasible", | ||
"code": { | ||
"impacts": { | ||
"RELIABILITY": "MEDIUM" | ||
}, | ||
"attribute": "LOGICAL" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |