powershell/PSPossibleIncorrectComparisonWithNull is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
Description
To ensure that PowerShell performs comparisons correctly, the$null element should be on the left
side of the operator.
There are multiple reasons why this occurs:
$nullis a scalar value. When the value on the left side of an operator is a scalar, comparison operators return a Boolean value. When the value is a collection, the comparison operators return any matching values or an empty array if there are no matches in the collection.- PowerShell performs type casting on the right-hand operand, resulting in incorrect comparisons
when
$nullis cast to other scalar types.
$null is to place $null on the left side of the
operator so that a scalar comparison is performed.
How
Move$null to the left side of the comparison.