Skip to content

Commit a38bd7a

Browse files
Copilotjakebailey
andcommitted
Run format and fix lint issues
- Format code with dprint - Use Go 1.22+ integer range syntax in for loops Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent 835673e commit a38bd7a

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

internal/format/ternary_test.go

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
package format_test
22

33
import (
4-
"testing"
4+
"testing"
55

6-
"github.com/microsoft/typescript-go/internal/ast"
7-
"github.com/microsoft/typescript-go/internal/core"
8-
"github.com/microsoft/typescript-go/internal/format"
9-
"github.com/microsoft/typescript-go/internal/parser"
6+
"github.com/microsoft/typescript-go/internal/ast"
7+
"github.com/microsoft/typescript-go/internal/core"
8+
"github.com/microsoft/typescript-go/internal/format"
9+
"github.com/microsoft/typescript-go/internal/parser"
1010
)
1111

1212
func TestTernaryWithTabs(t *testing.T) {
13-
t.Parallel()
13+
t.Parallel()
1414

15-
// This is the original code with tabs for indentation
16-
// Using literal tab characters
17-
text := "const test = (a: string) => (\n\ta === '1' ? (\n\t\t10\n\t) : (\n\t\t12\n\t)\n)"
15+
// This is the original code with tabs for indentation
16+
// Using literal tab characters
17+
text := "const test = (a: string) => (\n\ta === '1' ? (\n\t\t10\n\t) : (\n\t\t12\n\t)\n)"
1818

19-
ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{
20-
EditorSettings: format.EditorSettings{
21-
TabSize: 4,
22-
IndentSize: 4,
23-
BaseIndentSize: 0,
24-
NewLineCharacter: "\n",
25-
ConvertTabsToSpaces: false, // Use tabs
26-
IndentStyle: format.IndentStyleSmart,
27-
TrimTrailingWhitespace: true,
28-
},
29-
}, "\n")
19+
ctx := format.WithFormatCodeSettings(t.Context(), &format.FormatCodeSettings{
20+
EditorSettings: format.EditorSettings{
21+
TabSize: 4,
22+
IndentSize: 4,
23+
BaseIndentSize: 0,
24+
NewLineCharacter: "\n",
25+
ConvertTabsToSpaces: false, // Use tabs
26+
IndentStyle: format.IndentStyleSmart,
27+
TrimTrailingWhitespace: true,
28+
},
29+
}, "\n")
3030

31-
sourceFile := parser.ParseSourceFile(ast.SourceFileParseOptions{
32-
FileName: "/test.ts",
33-
Path: "/test.ts",
34-
}, text, core.ScriptKindTS)
31+
sourceFile := parser.ParseSourceFile(ast.SourceFileParseOptions{
32+
FileName: "/test.ts",
33+
Path: "/test.ts",
34+
}, text, core.ScriptKindTS)
3535

36-
edits := format.FormatDocument(ctx, sourceFile)
37-
newText := applyBulkEdits(text, edits)
36+
edits := format.FormatDocument(ctx, sourceFile)
37+
newText := applyBulkEdits(text, edits)
3838

39-
// Check that we don't have mixed tabs and spaces
40-
// The formatted text should only use tabs for indentation
41-
lines := splitLines(newText)
42-
for i, line := range lines {
43-
if len(line) == 0 {
44-
continue
45-
}
46-
// Check that the line doesn't have spaces for indentation followed by tabs
47-
hasLeadingSpaces := false
48-
for j := 0; j < len(line); j++ {
49-
if line[j] == ' ' {
50-
hasLeadingSpaces = true
51-
} else if line[j] == '\t' {
52-
// If we already saw spaces and now see a tab, that's a problem
53-
if hasLeadingSpaces {
54-
t.Errorf("Line %d has mixed tabs and spaces: %q", i, line)
55-
}
56-
} else {
57-
// Hit non-whitespace
58-
break
59-
}
60-
}
61-
}
39+
// Check that we don't have mixed tabs and spaces
40+
// The formatted text should only use tabs for indentation
41+
lines := splitLines(newText)
42+
for i, line := range lines {
43+
if len(line) == 0 {
44+
continue
45+
}
46+
// Check that the line doesn't have spaces for indentation followed by tabs
47+
hasLeadingSpaces := false
48+
for j := range len(line) {
49+
if line[j] == ' ' {
50+
hasLeadingSpaces = true
51+
} else if line[j] == '\t' {
52+
// If we already saw spaces and now see a tab, that's a problem
53+
if hasLeadingSpaces {
54+
t.Errorf("Line %d has mixed tabs and spaces: %q", i, line)
55+
}
56+
} else {
57+
// Hit non-whitespace
58+
break
59+
}
60+
}
61+
}
6262
}
6363

6464
func splitLines(text string) []string {
65-
var lines []string
66-
start := 0
67-
for i := 0; i < len(text); i++ {
68-
if text[i] == '\n' {
69-
lines = append(lines, text[start:i])
70-
start = i + 1
71-
}
72-
}
73-
if start < len(text) {
74-
lines = append(lines, text[start:])
75-
}
76-
return lines
65+
var lines []string
66+
start := 0
67+
for i := range len(text) {
68+
if text[i] == '\n' {
69+
lines = append(lines, text[start:i])
70+
start = i + 1
71+
}
72+
}
73+
if start < len(text) {
74+
lines = append(lines, text[start:])
75+
}
76+
return lines
7777
}

0 commit comments

Comments
 (0)