Skip to content

UseProcessBlockForPipelineCommand returns a warning when pipeline behavior is explicitly disabled #1725

Open

Description

@Glober777

I've noticed that UseProcessBlockForPipelineCommand rule produces warning notifications when pipeline behavior (ValueFromPipeline, ValueFromPipelineByPropertyName) is explicitly disabled.

Steps to reproduce

Function Get-Number
{
    [CmdletBinding()]
    [OutputType([int])]
    Param(
        [Parameter(ValueFromPipeline=$false)]
        [int]
        $Number
    )

    $Number
}

Expected behavior

The rule should not report any findings

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseProcessBlockForPipelineCommand Warning      Test-PSSA. 8     Command accepts pipeline input but has not defined a
                                                 ps1              process block.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

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

Activity

  1. rjmholt commented on Oct 12, 2021

    @rjmholt
    Contributor

    I haven't verified this, but looking at the code I think it's a bit naive and should be fixed to look at the value:

    if (!namedArgument.ArgumentName.Equals("valuefrompipeline", StringComparison.OrdinalIgnoreCase)
    && !namedArgument.ArgumentName.Equals("valuefrompipelinebypropertyname", StringComparison.OrdinalIgnoreCase))

    It looks like it currently operates on the assumption that specifying the attribute is always going to be activating it, so the code should instead actually check the value and only issue a warning if it's true or a value isn't given (since that defaults to true in PowerShell with boolean attribute parameters).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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