Closed
Description
VSCode Version: 1.17.0
OS Edition: Windows 10 Pro
OS Version: 1703
OS Build: 15063.674
Ext Version: 1.4.3
1.17.2
b813d12980308015bcd2b3a2f6efa5c810c33ba5
Major Minor Build Revision
----- ----- ----- --------
1 4 1 0
ms-vscode.PowerShell@1.4.3
robertohuertasm.vscode-icons@7.15.0
Key : PSVersion
Value : 5.1.15063.674
Name : PSVersion
Key : PSEdition
Value : Desktop
Name : PSEdition
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name : PSCompatibleVersions
Key : BuildVersion
Value : 10.0.15063.674
Name : BuildVersion
Key : CLRVersion
Value : 4.0.30319.42000
Name : CLRVersion
Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion
Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion
Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion
Issue Description
PsScriptAnalyzer Falsely Recognizes Global Variable As Assigned But Not Used
Obviously not a critical issue but it is kind of annoying having that green squiggly line under a variable that WILL be used.
Repro Steps
- Open VS Code and create a PowerShell file (PowerShell extension installed obviously).
- Paste the below example code.
- Note that
$global:eventType
is underlined as a 'PSUseDeclaredVarsMoreThanAssignments' error.
function Write-ErrorDetails {
$global:eventType = 'Error'
Write-Error -Message 'An error happened.' -ErrorId $statusCode
}
try {
Write-Output 'hello world'
$statusCode = 0
throw 'eventType variable is totally going to get used now!'
}
catch {
$statusCode = 1
Write-ErrorDetails
}
finally {
Write-EventLog -LogName 'Applicatoin' -Source 'MyScript' -EntryType $global:eventType
}
Metadata
Metadata
Assignees
Labels
No labels