PowerShell / PowerShell/PSScriptAnalyzer
false variable is assigned but never used recommendation (same as ticket #1354)
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
False report about unused variable
Steps to reproduce
$modified = $false
$source | ForEach-Object {
if ($_.LocalName -eq 'key') {
$modified = $true
}
}
return $modified
Another case:
$modified = $false
$source | ForEach-Object {
if ($_.LocalName -eq 'key') {
$modified = $true
}
}
if($modified) {
}
Expected behavior
No warning
Actual behavior
Warning:
The variable 'modified' is assigned but never used.PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)
Warning is present since long time ago
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.5.1
PSEdition Core
GitCommitId 7.5.1
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.23.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no repository files, tests, or entry points. Reproduce the warning with the provided PowerShell snippets, then compare the existing handling of PSUseDeclaredVarsMoreThanAssignments with ticket #1354. Done means both examples no longer emit the warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100