Skip to content

PSPlaceCloseBrace can't handle empty lines #1616

Open
@Jaykul

Description

@Jaykul

Basically, it gets fixed if I have:

}
else {

But it doesn't get fixed if I have:

}

else {

And I would really like it to be able to handle:

}
# An explanation of the next code block
else {

And format it like:

} else {
    # An explanation of the next code block

Steps to reproduce

Invoke-Formatter {
if (Test-Path ReadMe.md) {
    Show-Markdown ReadMe.md
}

elseif (Test-Path ReadMe*) {
    Get-Item ReadMe* | Select-Object -First 1 | Get-Content
} 
} -Settings @{
  Rules = @{
    PSPlaceCloseBrace = @{
      Enable = $true
      NoEmptylineBefore = $true
      NewLineAfter = $false
    }
  }
}

Expected behavior

It should output

if (Test-Path ReadMe.md) {
    Show-Markdown ReadMe.md
} elseif (Test-Path ReadMe*) {
    Get-Item ReadMe* | Select-Object -First 1 | Get-Content
} 

Actual behavior

if (Test-Path ReadMe.md) {
    Show-Markdown ReadMe.md
}

elseif (Test-Path ReadMe*) {
    Get-Item ReadMe* | Select-Object -First 1 | Get-Content
} 

Environment data

> $PSVersionTable
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
1.18.1
1.18.0
1.17.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions