From 9ca06937fa0ae7a5b49aaec84006355f39e086a4 Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Wed, 19 Mar 2025 18:20:06 -0500 Subject: [PATCH 1/3] Add configuration instructions (again) --- docs/Rules/UseCorrectCasing.md | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/docs/Rules/UseCorrectCasing.md b/docs/Rules/UseCorrectCasing.md index 6afcb3a4b..09ca084be 100644 --- a/docs/Rules/UseCorrectCasing.md +++ b/docs/Rules/UseCorrectCasing.md @@ -1,6 +1,6 @@ --- description: Use exact casing of cmdlet/function/parameter name. -ms.date: 06/28/2023 +ms.date: 03/19/2025 ms.topic: reference title: UseCorrectCasing --- @@ -10,10 +10,16 @@ title: UseCorrectCasing ## Description -This is a style formatting rule. PowerShell is case insensitive where applicable. The casing of -cmdlet names or parameters does not matter but this rule ensures that the casing matches for -consistency and also because most cmdlets/parameters start with an upper case and using that -improves readability to the human eye. +This is a style/formatting rule. PowerShell is case insensitive wherever possible, so the casing of +cmdlet names, parameters, keywords and operators does not matter. This rule nonetheless ensures +consistent casing for clarity and readability. Using lowercase keywords helps distinguish them from +commands. Using lowercase operators helps distinguish them from parameters. + +## How + +- Use exact casing for type names. +- Use exact casing of the cmdlet and its parameters. +- Use lowercase for language keywords and operators. ## Configuration @@ -28,36 +34,33 @@ Rules = @{ } ``` -### Enable: bool (Default value is `$false`) +### Parameters + +#### Enable: bool (Default value is `$false`) Enable or disable the rule during ScriptAnalyzer invocation. -### CheckCommands: bool (Default value is `$true`) +#### CheckCommands: bool (Default value is `$true`) If true, require the case of all operators to be lowercase. -### CheckKeyword: bool (Default value is `$true`) +#### CheckKeyword: bool (Default value is `$true`) If true, require the case of all keywords to be lowercase. -### CheckOperator: bool (Default value is `$true`) +#### CheckOperator: bool (Default value is `$true`) If true, require the case of all commands to match their actual casing. -## How - -Use exact casing of the cmdlet and its parameters, e.g. -`Invoke-Command { 'foo' } -RunAsAdministrator`. - -## Example +## Examples -### Wrong +### Wrong way ```powershell invoke-command { 'foo' } -runasadministrator ``` -### Correct +### Correct way ```powershell Invoke-Command { 'foo' } -RunAsAdministrator From 0f4c180c931e6b016dfe973004dbe4c8005560fc Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Wed, 19 Mar 2025 19:36:25 -0500 Subject: [PATCH 2/3] Add example for keyword --- docs/Rules/UseCorrectCasing.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/Rules/UseCorrectCasing.md b/docs/Rules/UseCorrectCasing.md index 09ca084be..487f17ce9 100644 --- a/docs/Rules/UseCorrectCasing.md +++ b/docs/Rules/UseCorrectCasing.md @@ -57,11 +57,19 @@ If true, require the case of all commands to match their actual casing. ### Wrong way ```powershell +ForEach ($file in Get-childitem -Recurse) { + $file.Extension -eq '.txt' +} + invoke-command { 'foo' } -runasadministrator ``` ### Correct way ```powershell +foreach ($file in Get-ChildiItem -Recurse) { + $file.Extension -eq '.txt' +} + Invoke-Command { 'foo' } -RunAsAdministrator ``` From ceb1c517cdf19ccdfb9e6b4b9c5468619f418c8b Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Wed, 19 Mar 2025 19:36:57 -0500 Subject: [PATCH 3/3] Fix typo --- docs/Rules/UseCorrectCasing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Rules/UseCorrectCasing.md b/docs/Rules/UseCorrectCasing.md index 487f17ce9..1874a7a84 100644 --- a/docs/Rules/UseCorrectCasing.md +++ b/docs/Rules/UseCorrectCasing.md @@ -67,7 +67,7 @@ invoke-command { 'foo' } -runasadministrator ### Correct way ```powershell -foreach ($file in Get-ChildiItem -Recurse) { +foreach ($file in Get-ChildItem -Recurse) { $file.Extension -eq '.txt' }