epacke / BigIPReport

Overview of your loadbalancer configuration
https://loadbalancing.se
8 stars 2 forks source link

$null comparisons might be suspect #106

Closed timriker closed 6 years ago

timriker commented 6 years ago

VS Code is throwing warnings on some of the code checks where we have $foo -eq $null or -ne $null. This code might not do what we expect. Example here:

$object = @(1, $null, 2, $null)

# "not safe" comparison with $null, perhaps a mistake
if ($object -eq $null) {
    # -eq gets @($null, $null) which is evaluated to $true by if
    'This is called.'
}

# safe comparison with $null
if ($null -eq $object) {
    'This is not called.'
}

https://raw.githubusercontent.com/nightroman/PowerShellTraps/master/Basic/Comparison-operators-with-collections/looks-like-object-is-null.ps1