null-comparison-side
What it does
Section titled “What it does”Reports a -eq or -ne comparison (or a case variant, as -ceq) with $null on the right.
Why it matters
Section titled “Why it matters”When the left side is an array, -eq and -ne filter it and return the elements: @(1, 2) -eq $null is an empty array and @(1, 2) -ne $null is the whole array. The test does not say whether the value itself is $null.
To fix, write $null on the left: $null -eq $x.
Example
Section titled “Example”...$count = 1$x -eq $null$null -eq $xif ($a -ne $null -and $b -ceq $null) { }$x -eq $nullable$null = 1$global:LASTEXITCODE = 1...Configuration
Section titled “Configuration”powershell: lint: rules: null-comparison-side: warn # off, warn (default), errorEnabled by the presets: powershell/psscriptanalyzer.
Suppress one line with sudsy-disable-next-line null-comparison-side in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| psscriptanalyzer | PSPossibleIncorrectComparisonWithNull |
partial | The module does not report a left operand it knows to be a scalar (a parameter or variable of a non-array type); Sudsy has no types, so [string]$a … $a -eq $null is reported. A comparison whose expression also holds -and, -or or -xor at the same level is skipped (the expression is not split). No fix that swaps the operands. |