Skip to content

PSUseConsistentIndentation indents inconsistently in function body after param block #1241

Closed
@rjmholt

Description

@rjmholt

From @ebmarquez in PowerShell/vscode-powershell#1958.

Repro:

$script = @'
function verb-noun {
    <#
        .SYNOPSIS
        example

        .INPUTS
        String
        System.Management.Automation.PSCredential

        .OUTPUTS
        System.Management.Automation.PSCustomObject

        .NOTES

    #>
    [CmdLetBinding()]
    [OutputType([PSCustomObject])]
    Param(

        # Computer
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Computer,

        # Credential
        [Parameter(Mandatory = $true)]
        [System.Management.Automation.PSCredential]
        $Credential
    )

    $cmd = Get-ShowCommands | Where-Object { $_.Name -eq 'running-config' }
$result = Invoke-NetDeviceShowCommand -Computer $Computer -Credential $Credential -Command $cmd.CommandLine
Add-Member -InputObject $result -MemberType NoteProperty -Name "Name" -Value $cmd.Name
return $result
'@

$PSUseConsistentIndentation = @{ 
            Enable = 'true'
            IndentationSize     = 4;
             PipelineIndentation = 'IncreaseIndentationForFirstPipeline'; 
             Kind                = 'space'
        }
$rules = @{
    PSUseConsistentIndentation = $PSUseConsistentIndentation;
}

Invoke-Formatter -ScriptDefinition $script -Settings @{ 
    IncludeRules = @('PSUserConsistentIndentation')
    Rules        = $rules
}

Actual Output:

function verb-noun {
    <#
        .SYNOPSIS
        example

        .INPUTS
        String
        System.Management.Automation.PSCredential

        .OUTPUTS
        System.Management.Automation.PSCustomObject

        .NOTES

    #>
    [CmdLetBinding()]
    [OutputType([PSCustomObject])]
    Param(

        # Computer
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Computer,

        # Credential
        [Parameter(Mandatory = $true)]
        [System.Management.Automation.PSCredential]
        $Credential
    )

    $cmd = Get-ShowCommands | Where-Object { $_.Name -eq 'running-config' }
$result = Invoke-NetDeviceShowCommand -Computer $Computer -Credential $Credential -Command $cmd.CommandLine
Add-Member -InputObject $result -MemberType NoteProperty -Name "Name" -Value $cmd.Name
return $result
}

Notice $cmd = ... is indented differently to $result = ... onward.

I would expect $result = ... etc to indent as $cmd = ... has.

I'll let @ebmarquez follow up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions