Create rule S6975 (#3892)
* Create rule S6975 * SONARIAC-1424 Split S6956 RSPEC into 2 rules * Code review remarks --------- Co-authored-by: mstachniuk <mstachniuk@users.noreply.github.com> Co-authored-by: Marcin Stachniuk <marcin.stachniuk@sonarsource.com>
This commit is contained in:
parent
173a43b3dd
commit
848e7c2048
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"title": "The properties and elements inside a template should appear in the recommended order",
|
"title": "The properties should appear in the recommended order",
|
||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
== Why is this an issue?
|
== Why is this an issue?
|
||||||
|
|
||||||
According to the best practices defined by Azure, a consistent order of properties and elements in a templates is recommended.
|
According to the best practices defined by Azure, a consistent order of properties in a templates is recommended.
|
||||||
This makes it easier to read and understand the template.
|
This makes it easier to read and understand the template.
|
||||||
|
|
||||||
Not following this convention has no technical impact,
|
Not following this convention has no technical impact,
|
||||||
but will reduce the template's readability because most developers are used to the standard order.
|
but will reduce the template's readability because most developers are used to the standard order.
|
||||||
|
|
||||||
Sorting the resources according to deployment order is recommended as well, as this will convey the intent of the orchestration.
|
|
||||||
|
|
||||||
== How to fix it in ARM Templates
|
== How to fix it in ARM Templates
|
||||||
|
|
||||||
*Recommended order of the top-level template properties*:
|
*Recommended order of properties*:
|
||||||
|
|
||||||
[source,json]
|
[source,json]
|
||||||
----
|
----
|
||||||
@ -27,40 +25,9 @@ Sorting the resources according to deployment order is recommended as well, as t
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
*Recommended order of the resource properties*:
|
|
||||||
|
|
||||||
[source,json]
|
|
||||||
----
|
|
||||||
{
|
|
||||||
"resources": [
|
|
||||||
{
|
|
||||||
"comments": "if any",
|
|
||||||
"condition": true,
|
|
||||||
"scope": "% parent scope %",
|
|
||||||
"type": "Microsoft.Compute/virtualMachines",
|
|
||||||
"apiVersion": "2023-09-01",
|
|
||||||
"name": "resourceName",
|
|
||||||
"location": "[parameters('location')]",
|
|
||||||
"zones": [],
|
|
||||||
"sku": {},
|
|
||||||
"kind": "",
|
|
||||||
"scale": "",
|
|
||||||
"plan": {},
|
|
||||||
"identity": {},
|
|
||||||
"copy": {},
|
|
||||||
"dependsOn": [],
|
|
||||||
"tags": {},
|
|
||||||
"properties": {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
----
|
|
||||||
|
|
||||||
Any other properties or elements not listed here should be placed before the `properties` object for the resource.
|
|
||||||
|
|
||||||
== How to fix it in Bicep
|
== How to fix it in Bicep
|
||||||
|
|
||||||
*Recommended order of the top-level template properties*:
|
*Recommended order of elements*:
|
||||||
|
|
||||||
[source,bicep]
|
[source,bicep]
|
||||||
----
|
----
|
||||||
@ -75,31 +42,6 @@ module ...
|
|||||||
output ...
|
output ...
|
||||||
----
|
----
|
||||||
|
|
||||||
*Recommended order of the resource properties and decorators*:
|
|
||||||
|
|
||||||
[source,bicep]
|
|
||||||
----
|
|
||||||
@description
|
|
||||||
@batchSize
|
|
||||||
resource resourceName
|
|
||||||
parent
|
|
||||||
scope
|
|
||||||
name
|
|
||||||
location/extendedLocation
|
|
||||||
zones
|
|
||||||
sku
|
|
||||||
kind
|
|
||||||
scale
|
|
||||||
plan
|
|
||||||
identity
|
|
||||||
dependsOn
|
|
||||||
tags
|
|
||||||
properties
|
|
||||||
----
|
|
||||||
|
|
||||||
Any other decorated not listed here should be placed before the `resource` object and after the other decorators.
|
|
||||||
Any other properties or elements not listed here should be placed before the `properties` object for the resource.
|
|
||||||
|
|
||||||
== Resources
|
== Resources
|
||||||
=== Documentation
|
=== Documentation
|
||||||
|
|
||||||
@ -115,26 +57,11 @@ ifdef::env-github,rspecator-view[]
|
|||||||
|
|
||||||
=== Message
|
=== Message
|
||||||
|
|
||||||
In case of wrong order of top-level and resource elements:
|
Reorder the elements to match the recommended order.
|
||||||
|
|
||||||
* Reorder the elements to match the recommended order.
|
|
||||||
|
|
||||||
In case of wrong order in decorators:
|
|
||||||
|
|
||||||
Reorder the decorators to match the recommended order.
|
|
||||||
|
|
||||||
=== Highlighting
|
=== Highlighting
|
||||||
|
|
||||||
In general, we want to highlight all the keys of elements that are in the wrong order.
|
In general, we want to highlight the first key that is in the wrong order.
|
||||||
|
|
||||||
For wrong order in top-level elements:
|
|
||||||
|
|
||||||
* The first wrongly ordered key should be highlighted as primary issue and the others as secondary locations.
|
|
||||||
|
|
||||||
For wrong order in a resource:
|
|
||||||
|
|
||||||
* The name of the resource / key of the resource should be highlighted as a primary issues.
|
|
||||||
All the wrongly ordered key should be highlighted as secondary locations.
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
== Comments And Links
|
== Comments And Links
|
||||||
|
23
rules/S6975/azureresourcemanager/metadata.json
Normal file
23
rules/S6975/azureresourcemanager/metadata.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"title": "The resource elements should appear in the recommended order",
|
||||||
|
"type": "CODE_SMELL",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
],
|
||||||
|
"defaultSeverity": "Major",
|
||||||
|
"ruleSpecification": "RSPEC-6975",
|
||||||
|
"sqKey": "S6975",
|
||||||
|
"scope": "All",
|
||||||
|
"defaultQualityProfiles": ["Sonar way"],
|
||||||
|
"quickfix": "unknown",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "LOW"
|
||||||
|
},
|
||||||
|
"attribute": "CONVENTIONAL"
|
||||||
|
}
|
||||||
|
}
|
104
rules/S6975/azureresourcemanager/rule.adoc
Normal file
104
rules/S6975/azureresourcemanager/rule.adoc
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
== Why is this an issue?
|
||||||
|
|
||||||
|
According to the best practices defined by Azure, a consistent order of elements in a templates is recommended.
|
||||||
|
This makes it easier to read and understand the template.
|
||||||
|
|
||||||
|
Not following this convention has no technical impact,
|
||||||
|
but will reduce the template's readability because most developers are used to the standard order.
|
||||||
|
|
||||||
|
== How to fix it in ARM Templates
|
||||||
|
|
||||||
|
*Recommended order of the resource elements*:
|
||||||
|
|
||||||
|
[source,json]
|
||||||
|
----
|
||||||
|
{
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"comments": "if any",
|
||||||
|
"condition": true,
|
||||||
|
"scope": "% parent scope %",
|
||||||
|
"type": "Microsoft.Compute/virtualMachines",
|
||||||
|
"apiVersion": "2023-09-01",
|
||||||
|
"name": "resourceName",
|
||||||
|
"location": "[parameters('location')]",
|
||||||
|
"zones": [],
|
||||||
|
"sku": {},
|
||||||
|
"kind": "",
|
||||||
|
"scale": "",
|
||||||
|
"plan": {},
|
||||||
|
"identity": {},
|
||||||
|
"copy": {},
|
||||||
|
"dependsOn": [],
|
||||||
|
"tags": {},
|
||||||
|
"properties": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
Any other properties not listed here should be placed before the `properties` object for the resource.
|
||||||
|
|
||||||
|
== How to fix it in Bicep
|
||||||
|
|
||||||
|
*Recommended order of the resource elements and decorators*:
|
||||||
|
|
||||||
|
[source,bicep]
|
||||||
|
----
|
||||||
|
@description
|
||||||
|
@batchSize
|
||||||
|
resource resourceName
|
||||||
|
parent
|
||||||
|
scope
|
||||||
|
name
|
||||||
|
location/extendedLocation
|
||||||
|
zones
|
||||||
|
sku
|
||||||
|
kind
|
||||||
|
scale
|
||||||
|
plan
|
||||||
|
identity
|
||||||
|
dependsOn
|
||||||
|
tags
|
||||||
|
properties
|
||||||
|
----
|
||||||
|
|
||||||
|
Any other decorated not listed here should be placed before the `resource` object and after the other decorators.
|
||||||
|
Any other elements not listed here should be placed before the `properties` object for the resource.
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
* Azure quickstart templates best practices - https://github.com/Azure/azure-quickstart-templates/blob/master/1-CONTRIBUTION-GUIDE/best-practices.md#sort-order-of-properties[Sort order of properties]
|
||||||
|
|
||||||
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
|
'''
|
||||||
|
== Implementation Specification
|
||||||
|
(visible only on this page)
|
||||||
|
|
||||||
|
=== Message
|
||||||
|
|
||||||
|
In case of wrong order of resource elements:
|
||||||
|
|
||||||
|
* Reorder the elements to match the recommended order.
|
||||||
|
|
||||||
|
In case of wrong order in decorators:
|
||||||
|
|
||||||
|
* Reorder the decorators to match the recommended order.
|
||||||
|
|
||||||
|
=== Highlighting
|
||||||
|
|
||||||
|
For wrong order in a resource:
|
||||||
|
|
||||||
|
We want to highlight the first key that is in the wrong order.
|
||||||
|
|
||||||
|
For wrong order decorators:
|
||||||
|
|
||||||
|
We want to highlight the first decorator that is in the wrong order.
|
||||||
|
|
||||||
|
'''
|
||||||
|
== Comments And Links
|
||||||
|
(visible only on this page)
|
||||||
|
|
||||||
|
endif::env-github,rspecator-view[]
|
2
rules/S6975/metadata.json
Normal file
2
rules/S6975/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user