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
Add indented here-string and single line here-string #17483
base: master
Are you sure you want to change the base?
Conversation
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Since C# got this I believe we need follow C#. |
|
@iSazonov PowerShell is not C#. We can take all the good parts from C# but there's no need to take the bad parts as well. The C# docs for raw strings mention this:
why would we want to add the same limitation here if we can avoid it? |
|
Since this was not in C# but is now, it will raise questions for users. That is why it should be discussed. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

PR Summary
Fixes #2337
Fixes #13204
There were a lot of different ideas posted in this thread, and this is just my own personal preference/idea on how to solve this.
I am open to other ideas if that's what the team/community wants.
You can add as many
@signs as you want to the here-string, if you add 2 or more@signs you allow the string terminator to be indented like this:The line with the fewest leading whitespaces (not including empty lines) dictate how many whitespace characters are removed from each line so in the previous example the first line would have no spaces, and the third would have 4 spaces.
Single line here-strings are also supported:
Write-Host @'Hello world!'@like the multi-line variant you can add as many@signs as you want.There are 3 reasons why I picked multiple
@signs over multiple'.1: It's easier to visually easier to see/count if you write
@@@@@'VS@'''''especially when you also consider double quotes and all the different single/double quote variants that are also supported.2: If you decide to swap between a single quote and double quote here-string it's easier to just change 1 character in each end instead of multiple characters in each end.
3: In the case of single line strings it allows the string to start with any character. It quotes were used you wouldn't be able to start the string with a quote character because it would be counted as part of the "header" section of the here-string.
PR Context
It's annoying to not be able to match the surrounding indentation if you for example use a herestring inside a function. Even if the content doesn't care about the leading whitespace the string terminator does so you end up with an ugly little
'@if you try to indent all the code that can be indented.Sometimes when writing string filters you end up needing to quote values inside the string which means you either need to remember to escape or use the opposite quotes. It's nicer to just start a filter with @' or @" and no longer worry about having to escape characters inside the string.
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.(which runs in a different PS Host).