You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm aware that I can suppress this warnings by applying [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','')] attribute, but it is wrong, because I still want to receive warnings about other unused variables.
Actual behavior
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseDeclaredVarsMoreThanAssignment Warning test.ps1 1 The variable 'PSNativeCommandArgumentPassing' is assigned
s but never used.
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.20348
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.24.0
The text was updated successfully, but these errors were encountered:
Yep. It's the little things like this that sting. I sometimes work around it by adding a line like [void]$PSNativeCommandArgumentPassing or Write-Verbose $PSNativeCommandArgumentPassing but you're right that it shouldn't be necessary for preference variables. Does PSScriptAnalyzer maintain a list of ignored variable names for the PSUseDeclaredVarsMoreThanAssignment test?
Steps to reproduce
Save this script to a file
test.ps1
:Call
Invoke-ScriptAnalyzer
cmdlet:Expected behavior
Empty output; no warnings.
$PSNativeCommandArgumentPassing is a preference variable.
I'm aware that I can suppress this warnings by applying
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','')]
attribute, but it is wrong, because I still want to receive warnings about other unused variables.Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: