FormatPowershellCode icon indicating copy to clipboard operation
FormatPowershellCode copied to clipboard

Code indentation

Open vlariono opened this issue 9 years ago • 0 comments

Added code indentation for other types of enclosures, like @(), $(), (), []. It should make code easier for reading. For example the following flat code:

function Test{
param(
[parameter(Position = 0, 
Mandatory = $false, 
ValueFromPipeline=$true)]
[string]
$Path
)

#array
$a=@( 'this is first string',
'this is second string',
'this is third string'
)

#hash array
$h=@{ 'First' = 'String1'
'Second' = 'String2'
'Third' = 'String3'
}

#script block
$s={
"Hi there"
}

#Expression
$e=$("Here is some"
"expression"
)
}

Original formatting:

function Test{
    param(
    [parameter(Position = 0, 
    Mandatory = $false, 
    ValueFromPipeline=$true)]
    [string]
    $Path
    )
    
    #array
    $a=@( 'this is first string',
    'this is second string',
    'this is third string'
    )
    
    #hash array
    $h=@{ 'First' = 'String1'
        'Second' = 'String2'
        'Third' = 'String3'
    }
    
    #script block
    $s={
        "Hi there"
    }
    
    #Expression
    $e=$("Here is some"
    "expression"
    )
}

Param block, expression and array is still flat

Modified formatting:

function Test{
    param(
        [parameter(Position = 0, 
                Mandatory = $false, 
                ValueFromPipeline=$true)]
        [string]
        $Path
    )
    
    #array
    $a=@( 'this is first string',
        'this is second string',
        'this is third string'
    )
    
    #hash array
    $h=@{ 'First' = 'String1'
        'Second' = 'String2'
        'Third' = 'String3'
    }
    
    #script block
    $s={
        "Hi there"
    }
    
    #Expression
    $e=$("Here is some"
        "expression"
    )
}

Param block, expression and arrays are different. It looks like more natural formatting.

vlariono avatar Dec 04 '16 13:12 vlariono