diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md new file mode 100644 index 0000000..046a93b --- /dev/null +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md @@ -0,0 +1,44 @@ +--- +description: Avoid reserved words as function names +ms.date: 08/31/2025 +ms.topic: reference +title: AvoidReservedWordsAsFunctionNames +--- +# AvoidReservedWordsAsFunctionNames + +**Severity Level: Warning** + +## Description + +Avoid using reserved words as function names. Using reserved words as function names can cause +errors or unexpected behavior in scripts. + +## How to Fix + +Avoid using any of the reserved words as function names. Choose a different name that's not a +reserved word. + +See [about_Reserved_Words][01] for a list of reserved words in PowerShell. + +## Example + +### Wrong + +```powershell +# Function is a reserved word +function function { + Write-Host "Hello, World!" +} +``` + +### Correct + +```powershell +# myFunction is not a reserved word +function myFunction { + Write-Host "Hello, World!" +} +``` + + +[01]: /powershell/module/microsoft.powershell.core/about/about_reserved_words diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md index 06f27d2..da1058b 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md @@ -23,6 +23,7 @@ The PSScriptAnalyzer contains the following rule definitions. | [AvoidMultipleTypeAttributes1](./AvoidMultipleTypeAttributes.md) | Warning | Yes | | | [AvoidNullOrEmptyHelpMessageAttribute](./AvoidNullOrEmptyHelpMessageAttribute.md) | Warning | Yes | | | [AvoidOverwritingBuiltInCmdlets](./AvoidOverwritingBuiltInCmdlets.md) | Warning | Yes | Yes | +| [AvoidReservedWordsAsFunctionNames](./AvoidReservedWordsAsFunctionNames.md) | Warning | Yes | | | [AvoidSemicolonsAsLineTerminators](./AvoidSemicolonsAsLineTerminators.md) | Warning | No | | | [AvoidShouldContinueWithoutForce](./AvoidShouldContinueWithoutForce.md) | Warning | Yes | | | [AvoidTrailingWhitespace](./AvoidTrailingWhitespace.md) | Warning | Yes | | diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCorrectCasing.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCorrectCasing.md index 4fd8771..b73df64 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCorrectCasing.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCorrectCasing.md @@ -11,7 +11,7 @@ title: UseCorrectCasing ## Description 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 +cmdlet names, parameters, keywords and operators doesn't 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. @@ -34,23 +34,23 @@ Rules = @{ } ``` -### Parameters +## Parameters -#### Enable: bool (Default value is `$false`) +### 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. +If true, require the case of all command and parameter names to match their canonical casing. -#### 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. +If true, require the case of all operators to be lowercase. For example: `-eq`, `-ne`, `-gt` ## Examples @@ -58,7 +58,7 @@ If true, require the case of all commands to match their actual casing. ```powershell ForEach ($file in Get-childitem -Recurse) { - $file.Extension -eq '.txt' + $file.Extension -EQ '.txt' } invoke-command { 'foo' } -runasadministrator