FormatPowershellCode
FormatPowershellCode copied to clipboard
Code indentation
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.