Skip to content

Formatter issues with indenting when brace and paren present on same line #558

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

Closed
jasnic02 opened this issue Mar 16, 2017 · 5 comments
Closed
Labels
Area-Code Formatting Issue-Enhancement A feature request (enhancement).

Comments

@jasnic02
Copy link

System Details

  • Operating system name and version: Windows 10 Pro
  • VS Code version: 1.10.2
  • PowerShell extension version: 0.10
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.14393.953
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.953
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Each open brace or paren on the same line is being counted as in indent trigger resulting in too many indents. ValidateScript is the best example:

    param (
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        [ValidateScript({
            if ($_ -is [System.IO.FileInfo] -or $_ -is [string]) {
                if ([System.IO.Path]::GetExtension($_) -ne '.xml' -and [System.IO.Path]::GetExtension($_) -ne '.gz') {
                    throw 'Invalid file extension specified for the InputObject parameter.'
                }
            }
            else {
                throw 'Invalid input object specified.'
            }

            $true
        })]
        [Object[]]$InputObject
    )

becomes:

    param (
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        [ValidateScript({
                    if ($_ -is [System.IO.FileInfo] -or $_ -is [string]) {
                        if ([System.IO.Path]::GetExtension($_) -ne '.xml' -and [System.IO.Path]::GetExtension($_) -ne '.gz') {
                            throw 'Invalid file extension specified for the InputObject parameter.'
                        }
                    }
                    else {
                        throw 'Invalid input object specified.'
                    }

                    $true
            })]
        [Object[]]$InputObject
    )

Note the closing '})]' is also indented. I believe the brace/paren characters should only be counted once for indent calculations if they are on the same line?

@kapilmb
Copy link

kapilmb commented Mar 29, 2017

@jasnic02 Your guess is correct that the formatter is counting the paren and brace in calculating the indentation of the block. Couting a paren block ensures that something like a multi-line param block gets indented correctly.

We didn't think of this particular case and thanks for pointing it out.

@kapilmb kapilmb added the Issue-Enhancement A feature request (enhancement). label Mar 29, 2017
@kapilmb kapilmb added this to the Backlog milestone Mar 29, 2017
@kapilmb
Copy link

kapilmb commented Mar 29, 2017

#576 also raises the issue of not indenting nested closing paren/brace combination correctly.

@tyteen4a03
Copy link

An option for OTBS would be great.

@TylerLeonhardt TylerLeonhardt modified the milestone: Future May 24, 2018
@DarkLite1
Copy link

Duplicate with #576

@TylerLeonhardt
Copy link
Member

Thanks @DarkLite1! Yes, this looks like a duplicate. It will be fixed in the next version of PSScriptAnalyzer. Please see #576 for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Code Formatting Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

5 participants