Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rules/PlaceCloseBrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private List<CorrectionExtent> GetCorrectionsForBraceShouldHaveNewLineAfter(
var nextToken = tokens[closeBracePos + 1];
var closeBraceToken = tokens[closeBracePos];
var indentation = tokens[closeBracePos - 1].Kind == TokenKind.NewLine
? new String(' ', closeBraceToken.Extent.StartColumnNumber - 1)
? closeBraceToken.Extent.StartScriptPosition.Line.Substring(0, closeBraceToken.Extent.StartColumnNumber - 1)
: GetIndentation(tokens, closeBracePos, openBracePos);

// Also remove the whitespace between the close brace and the next token
Expand Down
19 changes: 19 additions & 0 deletions Tests/Rules/PlaceCloseBrace.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ function Test {
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
}

It "Should preserve tab indentation before a close brace" {
$def = @'
if ($true) {
$true
} else {
$false
}
'@
$expected = @'
if ($true) {
$true
}
else {
$false
}
'@
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
}

It "Should find a violation for a close brace followed by elseif" {
$def = @'
if (Test-Path "blah") {
Expand Down
Loading