Add implicit line continuance for named parameters and splatted collections (experimental feature) #9614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
Continuing the work that was started in PR #8938, this PR adds more implicit line continuance support to simplify scripting while further reducing the need for explicit line continuance using backtick. With these changes in place, users can span commands across multiple lines as long as the subsequent lines begin with named parameters or splatted collections.
Breaking Change Details
It is marked as experimental at the moment because it introduces a breaking change and there wasn't a better way to make it optional at this time. Before these changes, users could invoke a command whose name begins with a dash (
-), or a named unary operator in a statement, even on a line immediately following another command.For example, here is what can be done before these changes:
With this PR in place, and with the experimental feature enabled, here is what happens instead:
While command names beginning with dash are virtually non-existent, to the point where I don't know if any exist in Windows or Linux (searches seem to indicate that dashes as the first character are problematic when it comes to file names on Linux, so maybe that's why), named unary operators are part of PowerShell and are used frequently. With that in mind, I've opened an RFC for discussion on possibilities because I believe this feature adds significant value that is worth considering, even if it remains only optional.
PR Context
This PR helps because PowerShell has many long commands (especially since some command names are over 60 characters long!), with many, many parameters, and users often want to span those commands across multiple lines in their scripts, but the only way to do that in PS 6.x and earlier is to use backtick or splatting. Neither of those should be necessary. Splatting has a purpose (passing in a common set of parameters to multiple commands), but splatting should not be the solution to more intelligent line wrapping within scripts. Instead, PowerShell can simply identify implicit line continuance automatically by looking at the subsequent lines to determine if they start with a named parameter or a splatted collection, and if so, tread them as part of the same command.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.PSImplicitLineContinuanceForNamedParameters