Skip to content

PSUseProcessBlockForPipelineCommand : The rule is triggered once for each set name parameter present #1473

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

Closed
LaurentDardenne opened this issue May 5, 2020 · 3 comments

Comments

@LaurentDardenne
Copy link

The rule is triggered once for each set name parameter present.

Steps to reproduce

Function TestParameterSet{
  [CmdletBinding(DefaultParameterSetName = "Functionality3")]
  Param (
      [Parameter(ValueFromPipeline = $true,ParameterSetName="Functionality1")]
    [String] $Avariable,

      [Parameter(ParameterSetName="Functionality2")]
    [Switch] $Bvariable,

      [Parameter(ValueFromPipelineByPropertyName = $true,ParameterSetName="Functionality3")]
    [Switch] $Cvariable,

      [Parameter(ParameterSetName="Functionality1")]
      [Parameter(ValueFromPipelineByPropertyName = $true,ParameterSetName="Functionality2")]
      [Parameter(ParameterSetName="Functionality3")]
    [String] $Dvariable
  )

    Write-Verbose "Traitement..."
}

Expected behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseProcessBlockForPipelineCommand Warning      MixedVFP   5     Command accepts pipeline input but has not defined a
                                                 One by           process block.
                                                 PSN
                                                 Without pr
                                                 ocessblock
                                                 .ps1

Actual behavior


RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseProcessBlockForPipelineCommand Warning      MixedVFP   5     Command accepts pipeline input but has not defined a
                                                 One by           process block.
                                                 PSN
                                                 Without pr
                                                 ocessblock
                                                 .ps1
PSUseProcessBlockForPipelineCommand Warning      MixedVFP   11    Command accepts pipeline input but has not defined a
                                                 One by           process block.
                                                 PSN
                                                 Without pr
                                                 ocessblock
                                                 .ps1
PSUseProcessBlockForPipelineCommand Warning      MixedVFP   16    Command accepts pipeline input but has not defined a
                                                 One by           process block.
                                                 PSN
                                                 Without pr
                                                 ocessblock
                                                 .ps1

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.18362.752
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.18362.752}
BuildVersion                   10.0.18362.752
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.1
1.18.0
1.17.1

If I add a process block there are no more warnings.

@bergmeister
Copy link
Collaborator

thanks for the report. That sounds like something we could try to tweak

@bergmeister
Copy link
Collaborator

@LaurentDardenne If it should only trigger once, then what should the reported Extent be in the violation?. At the moment, it points out which parameters are the one that declare pipeline support. The Param block or function name (if available)? Highlighting the whole Param block might look odd in VS-Code due to the squigglies.

@LaurentDardenne
Copy link
Author

>> If it should only trigger once, then what should the reported Extent be in the violation?
The first Violation I think.
The Param block can contain one or more parameters using the pipeline (by value or by property name).
The presence of the process block does not trigger this rule and this for all the parameter definitions that could trigger it.
The param block contains many implicit or explicit rules, this is one.

>> At the moment, it points out which parameters are the one that declare pipeline support.
I agree, here the cardinality is 1..n (a process block for one or more parameters using the pipeline).
The question here is not which parameter uses the pipeline, but that a declaration of this type is ineffective if the process block is absent.

And if I am not mistaken the reverse rule is also possible:
https://github.com/LaurentDardenne/ParameterSetRules/blob/master/RuleDocumentation/MissingArgumentToManageIncomingPipelineObject.md

>> The Param block or function name (if available)?
The function name. But here I have not considered scriptblocks.

>> Highlighting the whole Param block might look odd in VS-Code due to the squigglies.
This is another problem I think, I may not be using VS-Code.
What would be strange would be to display 'here there is a problem', to us to know which one ;-)
If I am told 'A parameter using the pipeline requires a process block', I no longer need to search for the treasure.
That said I use VSCode, but I don't focus on problem notifications, since sometimes we have to specify in the code 'this, is not a problem' :-)

So for this rule, personally I want to know what is missing, not what triggers it.

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