Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upCan't suppress message for a particular script #1240
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-BarIssue #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
PSUseDeclaredVarsMoreThanAssignmentswarning. 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