PSSA complains about Suppression Message Attribute being used wrongly
jegannathanmaniganadan opened this issue · 2 comments
I have been getting this error from PSSA.
Invoke-ScriptAnalyzer : Suppression Message Attribute error at line 66 in MSFT_xExchDatabaseAvailabilityGroupMember.psm1 : Cannot find any Targets DSCMachineStatus that match the Scope Function to apply the SuppressMessageAttribute.
I wonder whether this is correct, applying SuppressMessageAttribute with function scope, but actually targeting a variable ?
At \DSCResources\MSFT_xExchDatabaseAvailabilityGroupMember\MSFT_xExchDatabaseAvailabilityGroupMember.psm1
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function', Target='DSCMachineStatus')]
Interesting. I played around with this, and I think the problem is that Target can't be scoped to a specific PowerShell variable. This issue seems to confirm. It looks like there's three other places in the module that attempt this suppression as well. I'm thinking maybe we should move any code that sets $global:DSCMachineStatus to 1 into a helper function, and then suppress this rule for the entire function. What do you think?
PS D:\GitHub\xExchange> findstr /linspc:"'PSUseDeclaredVarsMoreThanAssignments', ''" *.*
DSCResources\MSFT_xExchDatabaseAvailabilityGroupMember\MSFT_xExchDatabaseAvailabilityGroupMember.psm1:66: [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function', Target='DSCMachineStatus')]
DSCResources\MSFT_xExchJetstress\MSFT_xExchJetstress.psm1:50: [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function', Target='DSCMachineStatus')]
DSCResources\MSFT_xExchJetstressCleanup\MSFT_xExchJetstressCleanup.psm1:56: [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function', Target='DSCMachineStatus')]
Modules\xExchangeHelper.psm1:650: [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function', Target='DSCMachineStatus')]