Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got a bunch of these when loading a .ps1 file in VS Code:

$null should be on the left side of equality comparisons. (PSPossibleIncorrectComparisonWithNull)

Since I'm not a fan of the "if( $null -eq $someVar )" order, I'd like to suppress these warnings.

What I have tried:

I found this:

https://github.com/PowerShell/PSScriptAnalyzer#suppressing-rules

...which lead me to try to add the following near the top of my file:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectComparisonWithNull", Scope="Function", Target="*")]

...but clearly this is not how this is intended to be used, as the warnings don't go away...

Clicking on the "PowerShell" label on the bottom-right of the VS Code editor brings up a popup showing "Configure PS language-based setting", among other things, and in there, searching for "PSScriptAnalyzer", I found that I can enable/disable it altogether ("PowerShell > Script Analysis: Enable"). However, I'd like to disable just this one rule.

Anyone know where I'm supposed to do that?
Posted
Updated 22-Aug-19 6:35am

1 solution

Try adding that attribute directly above the line you want to suppress warnings for (as shown in this Stack Overflow answer) or check out this article about creating a PSScriptAnalyzerSettings.psd1 file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900