Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSSA complains about Suppression Message Attribute being used wrongly #407

Closed
jegannathanmaniganadan opened this issue Feb 7, 2019 · 2 comments · Fixed by #408
Closed
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@jegannathanmaniganadan
Copy link

jegannathanmaniganadan commented Feb 7, 2019

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')]

@mhendric
Copy link
Contributor

mhendric commented Feb 7, 2019

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')]

@mhendric mhendric added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Feb 7, 2019
@mhendric
Copy link
Contributor

mhendric commented Feb 7, 2019

Opened #408 to address this

@mhendric mhendric added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants