From 68a958f5cc18b6778b729121e5187b25f679a0dc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:57:47 +0100 Subject: [PATCH] Create rule S6803: Parameters with SupplyParameterFromQuery attribute should be used only in routable components (#3216) --- rules/S6803/csharp/metadata.json | 24 ++++++++++++++++ rules/S6803/csharp/rule.adoc | 49 ++++++++++++++++++++++++++++++++ rules/S6803/metadata.json | 2 ++ 3 files changed, 75 insertions(+) create mode 100644 rules/S6803/csharp/metadata.json create mode 100644 rules/S6803/csharp/rule.adoc create mode 100644 rules/S6803/metadata.json diff --git a/rules/S6803/csharp/metadata.json b/rules/S6803/csharp/metadata.json new file mode 100644 index 00000000000..30ebd378816 --- /dev/null +++ b/rules/S6803/csharp/metadata.json @@ -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" + } +} diff --git a/rules/S6803/csharp/rule.adoc b/rules/S6803/csharp/rule.adoc new file mode 100644 index 00000000000..8ce8a89d29a --- /dev/null +++ b/rules/S6803/csharp/rule.adoc @@ -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] +---- +

Component

+ +@code { + [Parameter] + [SupplyParameterFromQuery] // Noncompliant + public bool Param { get; set; } +} +---- + +==== Compliant solution + +[source,csharp,diff-id=1,diff-type=compliant] +---- +@page "/component" + +

Component

+ +@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] diff --git a/rules/S6803/metadata.json b/rules/S6803/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S6803/metadata.json @@ -0,0 +1,2 @@ +{ +}