Skip to content

Auto-formatting incorrectly places an opening curly bracket if there is a comment on the previous line #1082

Closed
@exchange12rocks

Description

@exchange12rocks

System Details

Windows 10 64-bit

code -v:
1.17.2
b813d12980308015bcd2b3a2f6efa5c810c33ba5

$pseditor.EditorServicesVersion:
Major  Minor  Build  Revision
-----  -----  -----  --------
1      5      0      0

code --list-extensions --show-versions:
jasonn-porch.gitlab-mr@1.3.0
ms-mssql.mssql@1.2.0
ms-vscode.PowerShell@1.5.0

$PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.16299.19
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.19
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with curly brackets auto-formatting in if and for blocks (could be other blocks affected as well): If there is a comment on a line where the block starts and the opening curly bracket is on the next line, the bracket is placed on the first line, after the comment, which breaks the block.

if ($true) # comment
{
    echo 'OK'
}

foreach ($a in $b) #comment
{
    echo $a
}

Expected Result

if ($true) { # comment
    echo 'OK'
}

foreach ($a in $b) { #comment
    echo $a
}

Actual Result

if ($true) # comment {
    echo 'OK'
}

foreach ($a in $b) #comment {
    echo $a
}

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