PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.85k stars 373 forks source link

`PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments)` on `Export-ModuleMember -Variable` #1950

Closed Malix-Labs closed 9 months ago

Malix-Labs commented 11 months ago

Prerequisites

Summary

PSScriptAnalyzer(PSUseDeclaredVarsMoreThanAssignments) on Export-ModuleMember -Variable

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.3.9
PSEdition                      Core
GitCommitId                    7.3.9
OS                             Microsoft Windows 10.0.22635
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.83.1
f1b07bd25dfad64b0167beb15359ae573aecd2cc
x64

Extension Version

ms-vscode.powershell@2023.9.5

Steps to Reproduce

$variable = 0
Export-ModuleMember -Variable variable

Visuals

The variable 'variable' is assigned but never used.

SydneyhSmith commented 9 months ago

Thanks for the issue @Malix-off, in this case the error message is actually correct-- although it's a little bit tricky. In this case Export-ModuleMember is not actually referencing the variable, it is just making available in the module space so while the name of the variable is used, the actual variable is not used. If you want to you can suppress this warning.