-
Notifications
You must be signed in to change notification settings - Fork 398
Description
There seems to be an issue with my understanding of message suppression, or there's a bug.
I have a source file that simply is a list of variables used in our environment that I want to include in some scripts. Since they're all assigned, but never used, ScriptAnalyzer throws up the appropriate message. Given that there's almost a hundred lines in there, it makes the output very messy (and VSCode messy too).
I've tried to suppress the message with
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Scope="Module")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Scope="Module", Target="*")]
and various types of scope (module, script, function etc.) and it only ever suppresses the warning for the next variable defined. I've attached a simple file to show the issue - the only message suppressed is the one for the DefaultDHCPServer.
If I add multiple Suppress lines, one before each variable declaration, it works, but the code gets very messy, very quickly.
What am I doing wrong or missing? Or is there an issue with the code?
Thanks.
Graham.
Set-StrictMode -Version Latest
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Scope="Module", Target="*")]
$DefaultDHCPServer = "server"
$DefaultDNSServer = "server"
$DefaultDomainName = "domain"