Skip to content

PsScriptAnalyzer Falsely Recognizes Global Variable As Assigned But Not Used #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
avelis26 opened this issue Oct 18, 2017 · 2 comments
Closed

Comments

@avelis26
Copy link

avelis26 commented Oct 18, 2017

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

  1. Open VS Code and create a PowerShell file (PowerShell extension installed obviously).
  2. Paste the below example code.
  3. 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
}
@rkeithhill
Copy link
Contributor

You should file this in the PSSA project.

@daviwil
Copy link
Contributor

daviwil commented Oct 25, 2017

Resolving as duplicate of PowerShell/PSScriptAnalyzer#698, please subscribe to that issue to be notified when the issue gets resolved. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants