Skip to content

PSPossibleIncorrectComparisonWithNull not checked inside DSC Configurations #1745

Open
@VirtualEvan

Description

@VirtualEvan

Steps to reproduce

if (@() -eq $null) { 'true' } else { 'false' }
if (@() -ne $null) { 'true' } else { 'false' }

Configuration Test
{
    if (@() -eq $null) { 'true' } else { 'false' }
    if (@() -ne $null) { 'true' } else { 'false' }
}

Expected behavior

All 4 comparisons produce Warnings

Actual behavior

# Only the first two comparisons produce Warnings

RuleName                              Severity ScriptName Line Message
--------                              -------- ---------- ---- -------
PSPossibleIncorrectComparisonWithNull Warning  test.ps1   1    $null should be on the left side of equality comparisons.
PSPossibleIncorrectComparisonWithNull Warning  test.ps1   2    $null should be on the left side of equality comparisons.

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.18362.1171
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.1171
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.20.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions