UseProcessBlockForPipelineCommand returns a warning when pipeline behavior is explicitly disabled
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
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:
https://github.com/PowerShell/PSScriptAnalyzer/blob/359f98ffcca36704bc439e7572a0945e3f3eedce/Rules/UseProcessBlockForPipelineCommand.cs#L48-L49
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).