Skip to content

Code formatting should place cuddled else on new line when openBraceOnSameLine is false  #508

Closed
PowerShell/PSScriptAnalyzer
#713
@Jaykul

Description

@Jaykul

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:

   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"
   }

to this:

    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 😀

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions