Open mrboring opened 5 years ago
@bergmeister Have you made any progress on this?
Just ran into this issue as well.
I'm getting these errors too, though I've noticed a difference in when the error is raised.
Example: I've a module with wrapper functions for VMware. I want to use the following suppression statement in order to ignore checks for $Global:DefaultVIServers
(this is set when a connection to VMware is established, so the module functions check to see if we're already connected and if not, throw a message):
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', 'Global:DefaultVIServers', Justification = 'false positive')]
Working example / passes checks ✅:
if($Global:DefaultVIServers.Count -eq 0) { }
Failing example ❌:
if($Null -eq $Global:DefaultVIServer) {}
Error:
Invoke-ScriptAnalyzer: Suppression Message Attribute error at line 4 in Get-ClusterStatistics.ps1 : Cannot find any DiagnosticRecord with the Rule Suppression ID Global:DefaultVIServers.
The workaround here (at least for me) is to change the checking condition. Hopefully it helps some people.
Steps to reproduce
Unzip this: PSScriptAnalyzer - Custom rule suppression error.zip
The ZIP contains:
Execute
Run Me.ps1
Expected behavior
No errors.
Actual behavior
VSCode
Working OK. Custom rule suppressed, no squigglies:
Commandline
Got these errors:
I exported the errors to
Errors.clixml
. This is in the attached ZIP.I set the custom rule to log the
DiagnoticRecord
. The log contained the following:The above shows that
DiagnosticRecord
with the requiredRuleSuppressionID
were available.Environment data