In an attempt to conform to the Allman style indenting preferred by my team, I set powershell.codeFormatting.newLineAfterOpenBrace": false and Format Document converted this:
```posh
if(Test-Path "C:Program Files (x86)PHP5.6.26CACert") {
$PEM = Get-Content $PEM.FullPath -raw
Add-Content "C:Program Files (x86)PHP5.6.26CACertrootCA.pem" $Pem -Encoding ascii
} else {
Write-Warning "Failed to deploy PHP cert"
}
to this:
```posh
if(Test-Path "C:\Program Files (x86)\PHP\5.6.26\CACert")
{
$PEM = Get-Content $PEM.FullPath -raw
Add-Content "C:\Program Files (x86)\PHP\5.6.26\CACert\rootCA.pem" $Pem -Encoding ascii
} else
{
Write-Warning "Failed to deploy PHP cert"
}
I don't know what you call that half-cuddled else, but I just call it wrong 馃槈
If people have set "powershell.codeFormatting.openBraceOnSameLine": false, you need to ditch the cuddled else as well -- or add a setting for elseOnSameLine 馃榾
@kapilmb looks like a minor bug in the brace formatting rule
P.S.: my vote is to not add the elseOnSameLine setting.
Just do full Allman style for openBraceOnSameLine = false and OTBS (aka K&R) with cuddled else otherwise.
Uh, if openBraceOnSameLine = true I still don't want a cuddled else/elseif/catch/finally. So if the formatting is doing that now, I would prefer a setting disable that.
As long as I can get the formatter to format to:
if ($true) {
...
}
else {
...
}
I'll be happy. :-)
@rkeithhill With PowerShell/PSScriptAnalyzer#713 checkin, the codeformatter will allow only the following options
"powershell.codeFormatting.openBraceOnSameLine": true
if (...) {
...
}
else {
...
}
"powershell.codeFormatting.openBraceOnSameLine": false
if (...)
{
...
}
else
{
...
}
"powershell.codeFormatting.ignoreOneLineBlock": true
if (...) {...} else {...}
And the new NewLineAfter setting is true by default, meaning that cuddled else is opt-in by setting NewLineAfter to false.
@daviwil We haven't exposed that switch via codeformatter - Should we expose that here? Then it would look something like this: '"powershell.codeFormatting.newLineAfterCloseBrace": true`
Yep, definitely.
PR #512 adds the newLineAfterCloseBrace switch .
This is a travesty 馃槣
if (...) {
...
}
else {
...
}
You're choosing "Stroustrup" (style one) over the One True Brace Style? With "cuddled else" like the OTBS, you can safely insert a line (even a blank line) anywhere you like without breaking things. Why push Stroustrup?
@Jaykul What do you think this is - JavaScript? :-) Picking a default brace style is sort of a no-win situation. I "_don't believe sermons, fairy tales or stories about a OTBS_" (name that movie). :-)
I think the best that can be done is provide settings to allow folks to configure brace style to their own taste. They can configure that setting both per user and per workspace. With that in mind, maybe we need a "powershell.codeFormatting.cuddleBrace": false or something to that effect. My preference would be that it defaults to false.
How can I get stroustrup style for my if else statement blocks, I'm going crazy here.
@ctsstc follow this issue, we're fixing it soon: https://github.com/PowerShell/vscode-powershell/issues/740
But before I go too far in assuming what you mean, can you give an example of what you're looking for?
@ctsstc Stroustrup and Allman are the only styles it does right now. Worst of the worst. 馃槢
I think it works like this:
"powershell.codeFormatting.openBraceOnSameLine": true,
"powershell.codeFormatting.newLineAfterOpenBrace": true,
"powershell.codeFormatting.newLineAfterCloseBrace": true,
"powershell.codeFormatting.openBraceOnSameLine": false,
"powershell.codeFormatting.newLineAfterOpenBrace": true,
"powershell.codeFormatting.newLineAfterCloseBrace": true,
@ctsstc your desired style is the default in our code formatter. Can you give an example of where our default formatting does not follow that style?
Oh wow, I've failed, I thought this was the main VSCode Repo; /facepalm...
And I was indeed trying to get it to do that for JS. It's hard to tell what's doing what sometimes when you've got so many extensions installed. I have no clue what a vanilla experience is or if I have conflicting extensions at some point.
No problem! Yeah, that's one of the downsides I suppose, each extension has its own way of configuring code formatting (if it's even supported). You might take a look at the "javascript.format.*" settings and see if you can find the setting you need there.
Most helpful comment
Uh, if
openBraceOnSameLine = trueI still don't want a cuddled else/elseif/catch/finally. So if the formatting is doing that now, I would prefer a setting disable that.As long as I can get the formatter to format to:
I'll be happy. :-)