Title: Indentation for lines after a pipe character · Issue #184 · PoshCode/PowerShellPracticeAndStyle · GitHub
Open Graph Title: Indentation for lines after a pipe character · Issue #184 · PoshCode/PowerShellPracticeAndStyle
X Title: Indentation for lines after a pipe character · Issue #184 · PoshCode/PowerShellPracticeAndStyle
Description: When we have multiple commands, each piping their output to one another, for readability / single-line width it's generally best to put each command on a different line; like so: Write-Verbose 'Before the stuff in the piped code' $myArra...
Open Graph Description: When we have multiple commands, each piping their output to one another, for readability / single-line width it's generally best to put each command on a different line; like so: Write-Verbose 'Bef...
X Description: When we have multiple commands, each piping their output to one another, for readability / single-line width it's generally best to put each command on a different line; like so: Write-Verbose ...
Opengraph URL: https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/184
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Indentation for lines after a pipe character","articleBody":"When we have multiple commands, each piping their output to one another, for readability / single-line width it's generally best to put each command on a different line; like so:\r\n\r\n```powershell\r\nWrite-Verbose 'Before the stuff in the piped code'\r\n$myArrayOfThings |\r\n Where-Object {$_.SomeText -like 'pattern*'} |\r\n ForEach-Object {[PSCustomObject]@{\r\n MyText = $_.SomeText -replace '^pattern', ''\r\n AnotherProperty = $_.SomethingElse\r\n }}\r\nWrite-Verbose 'No longer in the piped code'\r\n```\r\n\r\nShould we define a best practice / guideline for this scenario?\r\n\r\nGenerally I indent all lines after the initial pipe to show they're a continuation of the previous line. However I don't indent again after subsequent lines because there would be no additional benefit.\r\n\r\nThe downside with this approach is that there's no \"closing line\"; which looks nasty if you the following line is a close for a parent block; e.g. \r\n\r\n```powershell\r\nif ($someFlag) {\r\n $myArrayOfThings |\r\n Where-Object {$_.SomeText -like 'pattern*'} |\r\n ForEach-Object {[PSCustomObject]@{\r\n MyText = $_.SomeText -replace '^pattern', ''\r\n AnotherProperty = $_.SomethingElse\r\n }}\r\n} # here we 're now have 8 spaces between this line's indentation level and the preceding line's.\r\n```\r\n\r\nAn option to tidy this up could be to put a comment to represent the close of he piped \"block\" / maybe with something after the comment character to show it's a close for the piped input; e.g.\r\n\r\n```powershell\r\nif ($someFlag) {\r\n $myArrayOfThings |\r\n Where-Object {$_.SomeText -like 'pattern*'} |\r\n ForEach-Object {[PSCustomObject]@{\r\n MyText = $_.SomeText -replace '^pattern', ''\r\n AnotherProperty = $_.SomethingElse\r\n }}\r\n # |\r\n}\r\n```\r\n\r\nAnother option could be to put parentheses around the block.\r\n\r\n\r\n```powershell\r\nif ($someFlag) {\r\n ($myArrayOfThings |\r\n Where-Object {$_.SomeText -like 'pattern*'} |\r\n ForEach-Object {[PSCustomObject]@{\r\n MyText = $_.SomeText -replace '^pattern', ''\r\n AnotherProperty = $_.SomethingElse\r\n }}\r\n )\r\n}\r\n```\r\n\r\n\r\nDo others have any thoughts or preferences on how best to approach these scenarios?","author":{"url":"https://github.com/JohnLBevan","@type":"Person","name":"JohnLBevan"},"datePublished":"2023-10-23T14:12:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/184/PowerShellPracticeAndStyle/issues/184"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d68783d9-8985-ba63-479b-3fedfa9e9725 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB9A:DF89D:6B7F4F:93F554:69775581 |
| html-safe-nonce | aea6f6dab690612a3085fcbed26ee8fe22103d2420bc7431f7a2f35fc652155e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjlBOkRGODlEOjZCN0Y0Rjo5M0Y1NTQ6Njk3NzU1ODEiLCJ2aXNpdG9yX2lkIjoiMTAwNjY2NDY2NzIxODAwNzQyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e3a43e6c82300b56928f6139948c4bb0b3ab5c56f5caead6485ad811f295606d |
| hovercard-subject-tag | issue:1957275516 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PoshCode/PowerShellPracticeAndStyle/184/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e03213eb6fd044fd4c4c4be7837c94afe9fac0aa0fb56a57770c994298b097b6/PoshCode/PowerShellPracticeAndStyle/issues/184 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e03213eb6fd044fd4c4c4be7837c94afe9fac0aa0fb56a57770c994298b097b6/PoshCode/PowerShellPracticeAndStyle/issues/184 |
| og:image:alt | When we have multiple commands, each piping their output to one another, for readability / single-line width it's generally best to put each command on a different line; like so: Write-Verbose 'Bef... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JohnLBevan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3310064f35a62c06a4024ba37f41c06836f39376a095c2dfd2c4b693c34965be |
| turbo-cache-control | no-preview |
| go-import | github.com/PoshCode/PowerShellPracticeAndStyle git https://github.com/PoshCode/PowerShellPracticeAndStyle.git |
| octolytics-dimension-user_id | 5641451 |
| octolytics-dimension-user_login | PoshCode |
| octolytics-dimension-repository_id | 17317123 |
| octolytics-dimension-repository_nwo | PoshCode/PowerShellPracticeAndStyle |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17317123 |
| octolytics-dimension-repository_network_root_nwo | PoshCode/PowerShellPracticeAndStyle |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 67d5f8d1d53c3cc4f49fc3bb8029933c3dc219e6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width