Skip to content

Commit 841dc4c

Browse files
Copilotbergmeister
andauthored
Add regression tests for attribute scriptblock indentation ([Attr({ ... })])
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent 128cac4 commit 841dc4c

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎Tests/Rules/UseConsistentIndentation.tests.ps1‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,48 @@ $(
10271027
'@
10281028
Invoke-Formatter -ScriptDefinition $idempotentScriptDefinition -Settings $settings | Should -Be $idempotentScriptDefinition
10291029
}
1030+
1031+
It "Should not double-indent attribute that opens a scriptblock: [ArgumentCompleter({" {
1032+
$def = @'
1033+
[ArgumentCompleter({
1034+
Param($commandName, $parameterName)
1035+
$validKeys = @('a', 'b')
1036+
$validKeys | Where-Object { $_ } | ForEach-Object { "$_=" }
1037+
})]
1038+
'@
1039+
$expected = @'
1040+
[ArgumentCompleter({
1041+
Param($commandName, $parameterName)
1042+
$validKeys = @('a', 'b')
1043+
$validKeys | Where-Object { $_ } | ForEach-Object { "$_=" }
1044+
})]
1045+
'@
1046+
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
1047+
}
1048+
1049+
It "Should not double-indent attribute that opens a scriptblock inside a param block: [ValidateScript({" {
1050+
$def = @'
1051+
function Test-Function {
1052+
param(
1053+
[ValidateScript({
1054+
$_ -gt 0
1055+
})]
1056+
$Value
1057+
)
1058+
}
1059+
'@
1060+
$expected = @'
1061+
function Test-Function {
1062+
param(
1063+
[ValidateScript({
1064+
$_ -gt 0
1065+
})]
1066+
$Value
1067+
)
1068+
}
1069+
'@
1070+
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
1071+
}
10301072
}
10311073

10321074
Context "When tabs instead of spaces are used for indentation" {

0 commit comments

Comments
 (0)