Skip to content

Commit 7b3de72

Browse files
Copilotbergmeister
andauthored
Preserve tab indentation when formatting branches (#2275)
* Initial plan * Preserve tab indentation when formatting branches Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent 810f339 commit 7b3de72

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎Rules/PlaceCloseBrace.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private List<CorrectionExtent> GetCorrectionsForBraceShouldHaveNewLineAfter(
278278
var nextToken = tokens[closeBracePos + 1];
279279
var closeBraceToken = tokens[closeBracePos];
280280
var indentation = tokens[closeBracePos - 1].Kind == TokenKind.NewLine
281-
? new String(' ', closeBraceToken.Extent.StartColumnNumber - 1)
281+
? closeBraceToken.Extent.StartScriptPosition.Line.Substring(0, closeBraceToken.Extent.StartColumnNumber - 1)
282282
: GetIndentation(tokens, closeBracePos, openBracePos);
283283

284284
// Also remove the whitespace between the close brace and the next token

‎Tests/Rules/PlaceCloseBrace.tests.ps1‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,25 @@ function Test {
226226
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
227227
}
228228

229+
It "Should preserve tab indentation before a close brace" {
230+
$def = @'
231+
if ($true) {
232+
$true
233+
} else {
234+
$false
235+
}
236+
'@
237+
$expected = @'
238+
if ($true) {
239+
$true
240+
}
241+
else {
242+
$false
243+
}
244+
'@
245+
Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected
246+
}
247+
229248
It "Should find a violation for a close brace followed by elseif" {
230249
$def = @'
231250
if (Test-Path "blah") {

0 commit comments

Comments
 (0)