GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — Add UseSingleValueFromPipelineParameter Rule by liamjpeters · Pull Request #2119 · PowerShell/PSScriptAnalyzer Conversation
|
You're right that most of the time someone does this, it's probably a mistake. But it is valid and there's a small use case of switching parameter sets based on the type of value received over the pipeline. So we can accept this as an optional rule, but it cannot be on by default. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Thanks so much for looking at this Andy 😀 I don't follow currently and I'm keen to. If you've the time to explain that use-case, I'd really appreciate that. If not, don't worry I'll get this changed to optional as you suggest. The rule checks that, at most, one parameter per set accepts pipeline input by value (my comment ommited "set"). So, if you're changing parameter sets based on the pipeline input - that's fine, you'd still only be accepting value binding on one parameter in that set? function Test-ValueFromPipeline { [CmdletBinding()] param ( [Parameter(ParameterSetName = 'One', ValueFromPipeline)] [string] $Parameter1, [Parameter(ParameterSetName = 'Two', ValueFromPipeline)] [int] $Parameter2 ) process { "$($PSCmdlet.ParameterSetName) was used." "Parameter1: $Parameter1!" "Parameter2: $Parameter2!" } } '8' | Test-ValueFromPipeline # One was used. # Parameter1: 8! # Parameter2: 0! 8 | Test-ValueFromPipeline # Two was used. # Parameter1: ! # Parameter2: 8! When multiple parameters accept pipeline input by value - binding without and with type coercion is attempted for each. If the binding succeeds for multiple parameters then you have the same data bound to multiple parameters? I guess one parameter could be a string and another could be an int, bound by coercion if the string is a valid integer? Is the use-case you're talking about when coercion for one such type would fail? e.g. An function Test-ValueFromPipeline { [CmdletBinding()] param ( [Parameter(ValueFromPipeline)] [System.Diagnostics.Process] $Parameter1, [Parameter(ValueFromPipeline)] [int] $Parameter2 ) process { "Parameter1: $($Parameter1.Name)!" "Parameter2: $Parameter2!" } } Get-Process -Name 'Code' | Select -First 1 | Test-ValueFromPipeline # Parameter1: Code! # Parameter2: 0! 1990 | Test-ValueFromPipeline # Parameter1: ! # Parameter2: 1990! You'd then make some check about If that's the case, why would the use of parameter sets not be encouraged? The 32 set limit? Complexity? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Patrick Meinecke (@SeeminglyScience) has the explanation (I was relaying it from a triage call). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
0abeb30 to
834059d
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good idea, happy to have it. Looks OK overall
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Christoph Bergmeister <[email protected]>
d77965e to
7b2667a
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Whelp, the auto accept-combined merge was incorrect (it looked right). Liam Peters (@liamjpeters) are you able to rebase this or otherwise fix the merge conflict? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Andy Jordan (@andyleejordan) My hero ❤️. Thanks for sorting that out - I didn't get time to look at it yesterday |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.