Skip to content

PSReviewUnusedParameter fails to look for parameter usage inside 'where-object's #1526

@EklipZgit

Description

@EklipZgit

Steps to reproduce

# ReproPSReviewUnusedParameterBug.ps1
function Remove-Something
{
    [CmdletBinding(
        DefaultParameterSetName = 'Component'
    )]
    [Alias('Delete-Something')]
    param(

        # Setting to Remove
        [Alias(
            'Name'
        )]
        [Parameter(
            Mandatory,
            ValueFromPipelineByPropertyName
        )]
        [ValidateNotNullOrEmpty()]
        [string]
        $Setting
    )

    process
    {
        foreach ($file in Get-ChildItem -Path "somewhere" -Recurse -Filter "*.json")
        {
            $contentObj = Get-Content -Path $file.FullName -Raw | ConvertFrom-Json

            $null = $contentObj.AppSettings | Where-Object { $_.Name -eq $Setting }

            $contentObj.AppSettings = @($contentObj.AppSettings | Where-Object { $_.Name -ne $Setting })
        }
    }
}


# Analyze the above file
Invoke-ScriptAnalyzer -Path $pathTo\ReproPSReviewUnusedParameterBug.ps1

Expected behavior

Doesn't say I have an unused parameter

Actual behavior

Says I have an unused parameter

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.16299.1146
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.1146
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.19.0
1.18.3
1.18.0
1.16.1

(but 1.19.0 is the one that has this issue, I have modules failing scriptanalyzer tests for the first time due to this update now)

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