Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
EklipZgit opened this issue Jun 16, 2020 · 2 comments

Comments

@EklipZgit
Copy link

EklipZgit commented Jun 16, 2020

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)
@ghost ghost added the Needs: Triage 🔍 label Jun 16, 2020
@bergmeister
Copy link
Collaborator

Thanks for taking the time to provide details.
This is a known issue and I'd say is a duplicate of #1472

@ghost
Copy link

ghost commented Jun 17, 2020

This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes.

@ghost ghost closed this as completed Jun 17, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants