-
Notifications
You must be signed in to change notification settings - Fork 395
Issue with Message suppression #875
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
Comments
@gmitch64 : Assuming you have a PowerShell script that you call directly has e.g.
Please let me know if this answered your question. |
Thanks, that seems to make it work as I expected it. What I am missing is my understanding of my I need to specify a Param() for it, and why it needs to be the first lines in the script. The more you learn, the more there is that you need to learn :) Thanks very much for the solution, and for giving me more work to do :) |
@gmitch64 You're welcome, I am glad it worked out for you. PSSA works by parsing PowerShell scripts as the PowerShell AST (abstract syntax tree), which are publicly available classes from the internals of PowerShell itself. The code that parses the script is here and you see here that it parses the script as scriptblock and function asts, therefore the |
@bergmeister Thanks for the explanation. I'll upvote issue 849, as it would be useful I think. I'll mark this issue as closed. Thanks. |
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.
The text was updated successfully, but these errors were encountered: