diff --git a/RuleDocumentation/README.md b/RuleDocumentation/README.md index 551ad55f5..d296d1d16 100644 --- a/RuleDocumentation/README.md +++ b/RuleDocumentation/README.md @@ -50,6 +50,7 @@ |[UseApprovedVerbs](./UseApprovedVerbs.md) | Warning | | |[UseBOMForUnicodeEncodedFile](./UseBOMForUnicodeEncodedFile.md) | Warning | | |[UseCmdletCorrectly](./UseCmdletCorrectly.md) | Warning | | +|[UseConsistentCasing](./UseConsistentCasing.md) | Information | | |[UseCorrectCasing](./UseCorrectCasing.md) | Information | | |[UseDeclaredVarsMoreThanAssignments](./UseDeclaredVarsMoreThanAssignments.md) | Warning | | |[UseLiteralInitializerForHashtable](./UseLiteralInitializerForHashtable.md) | Warning | | diff --git a/RuleDocumentation/UseConsistentCasing.md b/RuleDocumentation/UseConsistentCasing.md new file mode 100644 index 000000000..409b9da22 --- /dev/null +++ b/RuleDocumentation/UseConsistentCasing.md @@ -0,0 +1,25 @@ +# UseConsistentCasing + +**Severity Level: Information** + +## Description + +This is a style/formatting rule. PowerShell is case insensitive where applicable. The casing of keywords and operators does not matter but this rule ensures the use of lowercase for consistency and also because it helps distinguish keywords from commands (e.g. `foreach` is a keyword, but `ForEach-Object` is the command) and parameters (which should start with a capital letter). + +## How + +Use lowercase for language keywords and operators of the cmdlet and its parameters. + +## Example + +### Wrong + +``` PowerShell +ForEach($file IN Get-ChildItem) { $file } +``` + +### Correct + +``` PowerShell +foreach($file in Get-ChildItem) { $file } +``` diff --git a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 index e5e2159bd..a8ad0b9a2 100644 --- a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 +++ b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 @@ -63,7 +63,7 @@ Describe "Test Name parameters" { It "get Rules with no parameters supplied" { $defaultRules = Get-ScriptAnalyzerRule - $expectedNumRules = 65 + $expectedNumRules = 66 if ($PSVersionTable.PSVersion.Major -le 4) { # for PSv3 PSAvoidGlobalAliases is not shipped because @@ -159,7 +159,7 @@ Describe "TestSeverity" { It "filters rules based on multiple severity inputs"{ $rules = Get-ScriptAnalyzerRule -Severity Error,Information - $rules.Count | Should -Be 18 + $rules.Count | Should -Be 19 } It "takes lower case inputs" {