-
Notifications
You must be signed in to change notification settings - Fork 394
Can't suppress message for a particular script #1240
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
As an aside, if it isn't easy to have an attribute at the global script level, then maybe PSSA could use a comment convention e.g.:
and
The problem, I think, is that for this to work it would require a change to PowerShell (maybe v7) to recognize
See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma and https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning Now, these are not "compiler directives" so perhaps |
Are you putting that attribute on a |
No. Just at the top of the file. I tried putting it on an empty |
Yeah, actually, just tested ... it looks like the suppression only works on named functions. |
PSSA is looking for a [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]
param()
$unused1 = Get-Foo
$unused2 = Get-Bar Issue #849 tracks more sophisticated suppression syntax |
Oh, and also: #1295 |
Before submitting a bug report:
Steps to reproduce
Create a script with just variable definitions. This is a script you will dot source into a more complex script. Now when you analyze the script you will get a
PSUseDeclaredVarsMoreThanAssignments
warning. Suppressing these warnings one-by-one in such a file is a PITA and really makes this file that is supposed to be simple for my users to update, much more intimidating.Expected behavior
I expected a single suppress message declaration at the top of the file to work:
Actual behavior
This had no impact. The only way I can get this to work is to put this attribute (modified to remove the last two params) before every single variable declaration. And no, I don't want to disable this rule for all files, just this one file.
Environment data
The text was updated successfully, but these errors were encountered: