diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md index 11d078d..a9c5963 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md @@ -1,6 +1,6 @@ --- description: Avoid exclaim operator -ms.date: 03/26/2024 +ms.date: 05/28/2026 ms.topic: reference title: AvoidExclaimOperator --- @@ -10,28 +10,32 @@ title: AvoidExclaimOperator ## Description -Avoid using the negation operator (`!`). Use `-not` for improved readability. +This rule detects the use of the negation operator exclamation mark (`!`) and recommends using the +`-not` operator instead for improved readability and consistency with PowerShell conventions. -> [!NOTE] -> This rule is not enabled by default. The user needs to enable it through settings. +The `-not` operator is more explicit and aligns with PowerShell's verbose style, making code +easier to understand at a glance. -## How to Fix +This rule is **disabled** by default. Enable it explicitly during ScriptAnalyzer invocation if +desired. ## Example -### Wrong +### Noncompliant ```powershell $MyVar = !$true ``` -### Correct +### Compliant ```powershell $MyVar = -not $true ``` -## Configuration +## Configure rule + +To enable this rule, run the following command: ```powershell Rules = @{ @@ -41,8 +45,12 @@ Rules = @{ } ``` -### Parameters +## Parameters + +### Enable + +Enables (`$true`) the rule during ScriptAnalyzer invocation. -- `Enable`: **bool** (Default value is `$false`) +### Disable - Enable or disable the rule during ScriptAnalyzer invocation. +Disables (`$false`) the rule during ScriptAnalyzer invocation. Default value is `$false`. diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md index 5157ec6..2316ca8 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md @@ -1,6 +1,6 @@ --- description: Avoid global aliases. -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidGlobalAliases --- @@ -10,28 +10,29 @@ title: AvoidGlobalAliases ## Description -Globally scoped aliases override existing aliases within the sessions with matching names. This name -collision can cause difficult to debug issues for consumers of modules and scripts. +Global aliases can override existing aliases in the current session. This override +creates naming conflicts that lead to hard to diagnose problems for module and script consumers. -To understand more about scoping, see `Get-Help about_Scopes`. - -**NOTE** This rule is not available in PowerShell version 3 or 4 because it uses the +This rule is not available in PowerShell version 3 or 4 because it uses the `StaticParameterBinder.BindCommand` API. -## How - -Use other scope modifiers for new aliases. +Instead of using the Global scope, use other scope modifiers such as `Local` or `Process` when +creating new aliases. To learn more, see [about_Scopes][01]. ## Example -### Wrong +### Noncompliant ```powershell New-Alias -Name Name -Value Value -Scope Global ``` -### Correct +### Compliant ```powershell New-Alias -Name Name1 -Value Value ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md index 929466c..9f5a4da 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md @@ -10,25 +10,27 @@ title: AvoidGlobalFunctions ## Description -Globally scoped functions override existing functions within the sessions with matching names. This -name collision can cause difficult to debug issues for consumers of modules. +Global functions can unintentionally override existing functions in the session, leading to +unexpected behavior and name collisions. Name collisions make it difficult for module consumers to +diagnose issues and maintain code reliability. -To understand more about scoping, see `Get-Help about_Scopes`. - -## How - -Use other scope modifiers for functions. +To avoid this issue, define functions without the global scope modifier, or use other appropriate +scope modifiers. To learn more, see [about_Scopes][01]. ## Example -### Wrong +### Noncompliant ```powershell function global:functionName {} ``` -### Correct +### Compliant ```powershell function functionName {} ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md index 7fa0f6d..d7aa8aa 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md @@ -1,6 +1,6 @@ --- description: No Global Variables -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidGlobalVars --- @@ -20,15 +20,12 @@ Globally scoped variables include: - Preference variables - Variables, aliases, and functions that are in your PowerShell profiles -To understand more about scoping, see `Get-Help about_Scopes`. - -## How - -Use other scope modifiers for variables. +Use local or script scope for variables instead of global scope. To learn more, see +[about_Scopes][01]. ## Example -### Wrong +### Noncompliant ```powershell $Global:var1 = $null @@ -38,7 +35,7 @@ function Test-NotGlobal ($var) } ``` -### Correct +### Compliant ```powershell $var1 = $null @@ -47,3 +44,7 @@ function Test-NotGlobal ($var1, $var2) $a = $var1 + $var2 } ``` + + + +[01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md index 6049e86..1654095 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md @@ -1,6 +1,6 @@ --- description: Avoid Invoking Empty Members -ms.date: 06/28/2023 +ms.date: 05/28/2026 ms.topic: reference title: AvoidInvokingEmptyMembers --- @@ -10,23 +10,22 @@ title: AvoidInvokingEmptyMembers ## Description -Invoking non-constant members can cause potential bugs. Please double check the syntax to make sure -that invoked members are constants. +Invoking dynamically constructed member names can introduce unexpected behavior and runtime errors. +Ensure that member invocations use constant, literal member names rather than expressions that are +evaluated at runtime. -## How - -Provide the requested members for a given type or class. +Replace dynamic member name expressions with constant member names for the target type or class. ## Example -### Wrong +### Noncompliant ```powershell $MyString = 'abc' $MyString.('len'+'gth') ``` -### Correct +### Compliant ```powershell $MyString = 'abc' diff --git a/reference/docs-conceptual/toc.yml b/reference/docs-conceptual/toc.yml index 1fbfbd3..7f05ada 100644 --- a/reference/docs-conceptual/toc.yml +++ b/reference/docs-conceptual/toc.yml @@ -43,6 +43,8 @@ items: href: PSScriptAnalyzer/Rules/AvoidDefaultValueForMandatoryParameter.md - name: AvoidDefaultValueSwitchParameter href: PSScriptAnalyzer/Rules/AvoidDefaultValueSwitchParameter.md + - name: AvoidExclaimOperator + href: PSScriptAnalyzer/Rules/AvoidExclaimOperator.md - name: AvoidGlobalAliases href: PSScriptAnalyzer/Rules/AvoidGlobalAliases.md - name: AvoidGlobalFunctions