Skip to content

Commit

Permalink
Clarify the limitations of the rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler committed Mar 6, 2024
1 parent a66009b commit 0c0faf4
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Extra Variables
ms.custom: PSSA v1.21.0
ms.date: 06/28/2023
ms.date: 03/06/2024
ms.topic: reference
title: UseDeclaredVarsMoreThanAssignments
---
Expand Down Expand Up @@ -44,10 +44,13 @@ function Test
}
```

### Special case
### Special cases

The following example triggers the **PSUseDeclaredVarsMoreThanAssignments** warning because `$bar`
is not used within the scriptblock where it was defined.
The following examples trigger the **PSUseDeclaredVarsMoreThanAssignments** warning. This behavior
is a limitation of the rule. There is no way to avoid this false positive warnings.

In this case, the warning is triggered because `$bar` is not used within the scriptblock where it
was defined.

```powershell
$foo | ForEach-Object {
Expand All @@ -60,3 +63,11 @@ if($bar){
Write-Host 'Collection contained a false case.'
}
```

In the next example, the warning is triggered because `$errResult` isn't recognized as being used in
the `Write-Host` command.

```powershell
$errResult = $null
Write-Host 'Ugh:' -ErrorVariable errResult
```

0 comments on commit 0c0faf4

Please sign in to comment.