-
Notifications
You must be signed in to change notification settings - Fork 391
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
Need test to catch Pipeline-able input with missing process block #1368
Comments
@rjmholt Is there a reason the Parser does not throw in this case? |
The syntax here is perfectly valid, so it's not a syntax error. More than that, it's not what PowerShell deems a semantic error either, since those are things that are valid syntax but can't possibly have a non-error behaviour at runtime (for example Instead, we just need to write a simple rule that, when there's no process block on a |
I'd like to throw my hat in the ring here - please consider PR #1373 to address this issue. |
@EklipZgit I plagiarized your example code in the help doc for this rule - hope you don't mind. |
…#1373) * Add rule for missing process block #1368 * Fix build by regenerating strongly typed files by running '.\New-StronglyTypedCsFileForResx.ps1 Rules' * Update strongly typed resources via Visual Studio * minimise diff in resx file * refactor UseProcessBlockForPipelineCommands rule * add tests and docs for UseProcessBlockForPipelineCommands rule * Fix logic non-pipeline function and add test case * fixing some test failures * incrememt number of expected rules * fix style suggestions for PR #1373 * fix rule readme.md * clean diff for Strings.resx to avoid future merge conflicts * Fix last 2 rule documentation test failures by fixing markdown link * Update Rules/Strings.resx Co-Authored-By: Christoph Bergmeister [MVP] <c.bergmeister@gmail.com> * Update Rules/Strings.resx Co-Authored-By: Christoph Bergmeister [MVP] <c.bergmeister@gmail.com> * Update Rules/Strings.resx Co-Authored-By: Christoph Bergmeister [MVP] <c.bergmeister@gmail.com> * empty-commit to re-trigger CI due to sporadic failure * Update Rules/Strings.resx Co-Authored-By: Robert Holt <rjmholt@gmail.com> * Update Rules/Strings.resx Co-Authored-By: Robert Holt <rjmholt@gmail.com> * corrections to use process block rule and tests - candidate for merge * More style fixes for #1373 * update localized strings * replace implicitly typed vars
Awesome, thanks for taking a look at this! |
Currently you can create functions / cmdlets with parameters with ValueFromPipeline or ValueFromPipelineByPropertyName, but if you forget the process { } block, only the last pipeline object will be processed by the cmdlet, instead of all of them, resulting in unexpected behavior that can slip through the cracks unnoticed until you pipe a batch of objects to the commandlet and realize that it only processed one of them. PSScriptAnalyzer should default to warning developers to use the process { } block when they use ValueFromPipeline or ValueFromPipelineByPropertyName attributes in a function / cmdlet.
The text was updated successfully, but these errors were encountered: