diff --git a/rules/S1481/azureresourcemanager/metadata.json b/rules/S1481/azureresourcemanager/metadata.json index 7a73a41bfdf..0db3279e44b 100644 --- a/rules/S1481/azureresourcemanager/metadata.json +++ b/rules/S1481/azureresourcemanager/metadata.json @@ -1,2 +1,3 @@ { -} \ No newline at end of file + +} diff --git a/rules/S1481/azureresourcemanager/rule.adoc b/rules/S1481/azureresourcemanager/rule.adoc index 7103ee84920..af13e46d8eb 100644 --- a/rules/S1481/azureresourcemanager/rule.adoc +++ b/rules/S1481/azureresourcemanager/rule.adoc @@ -2,7 +2,8 @@ include::../rationale.adoc[] == How to fix it in ARM Templates -Remove the unused variable, after ensuring it is not part of an incomplete implementation leading to bugs. +The fix for this issue is straightforward. +Once you ensure the unused variable is not part of an incomplete implementation leading to bugs, you just need to remove it. === Code examples @@ -13,8 +14,8 @@ Remove the unused variable, after ensuring it is not part of an incomplete imple { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "variables": { - "virtualMachinesName": "[concat('virtualMachinesResource', uniqueString(resourceGroup().id))]", - "unusedVariable": "unusedValue" + "unusedVariable": "unusedValue", + "virtualMachinesName": "[uniqueString(resourceGroup().id)]" }, "resources": [ { @@ -34,7 +35,7 @@ Remove the unused variable, after ensuring it is not part of an incomplete imple { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "variables": { - "virtualMachinesName": "[concat('virtualMachinesResource', uniqueString(resourceGroup().id))]" + "virtualMachinesName": "[uniqueString(resourceGroup().id)]" }, "resources": [ { @@ -49,7 +50,8 @@ Remove the unused variable, after ensuring it is not part of an incomplete imple == How to fix it in Bicep -Remove the unused variable, after ensuring it is not part of an incomplete implementation leading to bugs. +The fix for this issue is straightforward. +Once you ensure the unused variable is not part of an incomplete implementation leading to bugs, you just need to remove it. === Code examples @@ -57,8 +59,8 @@ Remove the unused variable, after ensuring it is not part of an incomplete imple [source,bicep,diff-id=2,diff-type=noncompliant] ---- -var storageName = '${toLower(storageNamePrefix)}${uniqueString(resourceGroup().id)}' var unusedVariable = 'unusedValue' # Noncompliant +var virtualMachinesName = '${uniqueString(resourceGroup().id)}' resource demoAccount 'Microsoft.Compute/virtualMachines@2023-09-01' = { name: virtualMachinesName diff --git a/rules/S1481/rationale.adoc b/rules/S1481/rationale.adoc index d4fd886be70..1c51e74b962 100644 --- a/rules/S1481/rationale.adoc +++ b/rules/S1481/rationale.adoc @@ -6,14 +6,14 @@ An unused local variable is a variable that has been declared but is not used an Having unused local variables in your code can lead to several issues: -* Decreased Readability: Unused variables can make your code more difficult to read. They add extra lines and complexity, which can distract from the main logic of the code. +* *Decreased Readability*: Unused variables can make your code more difficult to read. They add extra lines and complexity, which can distract from the main logic of the code. -* Misunderstanding: When other developers read your code, they may wonder why a variable is declared but not used. This can lead to confusion and misinterpretation of the code's intent. +* *Misunderstanding*: When other developers read your code, they may wonder why a variable is declared but not used. This can lead to confusion and misinterpretation of the code's intent. -* Potential for Bugs: If a variable is declared but not used, it might indicate a bug or incomplete code. For example, if you declared a variable intending to use it in a calculation, but then forgot to do so, your program might not work as expected. +* *Potential for Bugs*: If a variable is declared but not used, it might indicate a bug or incomplete code. For example, if you declared a variable intending to use it in a calculation, but then forgot to do so, your program might not work as expected. -* Maintenance Issues: Unused variables can make code maintenance more difficult. If a programmer sees an unused variable, they might think it is a mistake and try to 'fix' the code, potentially introducing new bugs. +* *Maintenance Issues*: Unused variables can make code maintenance more difficult. If a programmer sees an unused variable, they might think it is a mistake and try to 'fix' the code, potentially introducing new bugs. -* Memory Usage: Although modern compilers are smart enough to ignore unused variables, not all compilers do this. In such cases, unused variables take up memory space, leading to inefficient use of resources. +* *Memory Usage*: Although modern compilers are smart enough to ignore unused variables, not all compilers do this. In such cases, unused variables take up memory space, leading to inefficient use of resources. In summary, unused local variables can make your code less readable, more confusing, and harder to maintain, and they can potentially lead to bugs or inefficient memory use. Therefore, it is best to remove them. diff --git a/rules/S6893/azureresourcemanager/metadata.json b/rules/S6893/azureresourcemanager/metadata.json index eaf2a9d4abe..6bb95191018 100644 --- a/rules/S6893/azureresourcemanager/metadata.json +++ b/rules/S6893/azureresourcemanager/metadata.json @@ -1,5 +1,5 @@ { - "title": "Use a hard-coded value for the apiVersion", + "title": "Use a constant value for the apiVersion", "type": "CODE_SMELL", "status": "ready", "remediation": { diff --git a/rules/S6893/azureresourcemanager/rule.adoc b/rules/S6893/azureresourcemanager/rule.adoc index d55db588972..e1aba1b7527 100644 --- a/rules/S6893/azureresourcemanager/rule.adoc +++ b/rules/S6893/azureresourcemanager/rule.adoc @@ -14,7 +14,7 @@ when the API version you set for a resource doesn't match the properties in your == How to fix it in ARM Templates -To avoid these issues, it is recommended to set the `apiVersion` to a hard-coded value for the resource type. +To avoid these issues, it is recommended to set the `apiVersion` to a constant value for the resource type. When creating a new template, we suggest you use the latest API version for a resource type. @@ -99,7 +99,7 @@ ifdef::env-github,rspecator-view[] === Message -Use a hard-coded value for the `apiVersion` of this resource. +Use a constant value for the `apiVersion` of this resource. === Highlighting