Skip to content

Commit b05216e

Browse files
Address PR feedback: remove unused markers and fix nil pointer crash
- Remove unused markers (/*1*/, /*2*/, /*3*/) from formatDocumentInPlace_test.go - Apply fix from PR #1993 to prevent nil pointer crash in indent.go when firstListChild is nil - Add comment about known trailing space issue (#1997) The indent.go fix prevents crashes when formatting ranges where the list has no first child. Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
1 parent a0c8f66 commit b05216e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

internal/format/indent.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ func getIndentationForNodeWorker(
6666
// }, { itself contributes nothing.
6767
// prop: 1 L3 - The indentation of the second object literal is best understood by
6868
// }) looking at the relationship between the list and *first* list item.
69-
listLine, _ := getStartLineAndCharacterForNode(firstListChild, sourceFile)
70-
listIndentsChild := firstListChild != nil && listLine > containingListOrParentStartLine
69+
var listIndentsChild bool
70+
if firstListChild != nil {
71+
listLine, _ := getStartLineAndCharacterForNode(firstListChild, sourceFile)
72+
listIndentsChild = listLine > containingListOrParentStartLine
73+
}
7174
actualIndentation := getActualIndentationForListItem(current, sourceFile, options, listIndentsChild)
7275
if actualIndentation != -1 {
7376
return actualIndentation + indentationDelta

internal/fourslash/tests/formatDocumentInPlace_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
func TestFormatDocumentInPlace(t *testing.T) {
1111
t.Parallel()
1212
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
13-
const content = `/*1*/for (;;) { }
14-
/*2*/for (var x;x<0;x++) { }
15-
/*3*/for (var x ;x<0 ;x++) { }`
13+
const content = `for (;;) { }
14+
for (var x;x<0;x++) { }
15+
for (var x ;x<0 ;x++) { }`
1616
f := fourslash.NewFourslash(t, nil /*capabilities*/, content)
1717
f.FormatDocument(t)
1818
// After formatting, verify the formatted content
19+
// Note: trailing space on last line is a known issue (see https://github.com/microsoft/typescript-go/issues/1997)
1920
f.CurrentFileContentIs(t, `for (; ;) { }
2021
for (var x; x < 0; x++) { }
2122
for (var x; x < 0; x++) { } `)

0 commit comments

Comments
 (0)