Skip to content

Commit 137ea43

Browse files
author
sutong.527608
committed
Fix code formatting with dprint
Run dprint fmt to fix formatting issues: - Add trailing comma in TypeScript function arguments - Move catch keyword to new line - Remove extra blank lines in Go test file - Add newline at end of files
1 parent 14b3a37 commit 137ea43

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

_extension/src/commands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ async function sortImports(client: Client): Promise<void> {
7777
// Execute the sort imports command on the server via LSP
7878
await client.executeCommand(
7979
"typescript-go.organizeImports",
80-
document.uri.toString()
80+
document.uri.toString(),
8181
);
8282
vscode.window.showInformationMessage("Imports sorted successfully");
83-
} catch (error) {
83+
}
84+
catch (error) {
8485
vscode.window.showErrorMessage(`Failed to sort imports: ${error}`);
8586
}
8687
}

internal/ls/organizeimports_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,4 @@ func (l *LanguageService) hasBlankLineBeforeStatement(file *ast.SourceFile, stmt
171171
}
172172

173173
return newlineCount >= 2
174-
}
174+
}

internal/ls/organizeimports_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ func TestCompareImportsOrRequireStatements_ModuleSpecifiers(t *testing.T) {
7373
for _, tt := range tests {
7474
t.Run(tt.name, func(t *testing.T) {
7575
t.Parallel()
76-
76+
7777
imports1 := parseImports(t, tt.import1)
7878
imports2 := parseImports(t, tt.import2)
79-
79+
8080
assert.Assert(t, len(imports1) == 1, "Expected 1 import in import1")
8181
assert.Assert(t, len(imports2) == 1, "Expected 1 import in import2")
82-
82+
8383
comparer := strings.Compare
8484
result := ls.CompareImportsOrRequireStatements(imports1[0], imports2[0], comparer)
85-
85+
8686
if tt.expected == 0 {
8787
assert.Equal(t, 0, result, "Expected imports to be equal")
8888
} else if tt.expected < 0 {
@@ -132,16 +132,16 @@ func TestCompareImportsOrRequireStatements_ImportKind(t *testing.T) {
132132
for _, tt := range tests {
133133
t.Run(tt.name, func(t *testing.T) {
134134
t.Parallel()
135-
135+
136136
imports1 := parseImports(t, tt.import1)
137137
imports2 := parseImports(t, tt.import2)
138-
138+
139139
assert.Assert(t, len(imports1) == 1, "Expected 1 import in import1")
140140
assert.Assert(t, len(imports2) == 1, "Expected 1 import in import2")
141-
141+
142142
comparer := strings.Compare
143143
result := ls.CompareImportsOrRequireStatements(imports1[0], imports2[0], comparer)
144-
144+
145145
if tt.expected < 0 {
146146
assert.Assert(t, result < 0, "Expected import1 < import2, got %d", result)
147147
} else if tt.expected > 0 {
@@ -175,7 +175,7 @@ import * as namespace from "namespace-lib";
175175
}
176176

177177
index := ls.GetImportDeclarationInsertIndex(imports, newImports[0], comparer)
178-
assert.Assert(t, index >= 0 && index <= len(imports),
178+
assert.Assert(t, index >= 0 && index <= len(imports),
179179
"Insert index %d out of range [0, %d]", index, len(imports))
180180
}
181181

@@ -222,7 +222,7 @@ func TestCompareImports_RelativeVsAbsolute(t *testing.T) {
222222
for _, tt := range tests {
223223
t.Run(tt.name, func(t *testing.T) {
224224
t.Parallel()
225-
225+
226226
var imports []*ast.Statement
227227
for _, imp := range tt.imports {
228228
parsed := parseImports(t, imp)
@@ -233,7 +233,7 @@ func TestCompareImports_RelativeVsAbsolute(t *testing.T) {
233233
comparer := func(a, b *ast.Statement) int {
234234
return ls.CompareImportsOrRequireStatements(a, b, strings.Compare)
235235
}
236-
236+
237237
for i := 0; i < len(imports); i++ {
238238
for j := i + 1; j < len(imports); j++ {
239239
if comparer(imports[i], imports[j]) > 0 {
@@ -245,14 +245,14 @@ func TestCompareImports_RelativeVsAbsolute(t *testing.T) {
245245
for i, want := range tt.want {
246246
wantImports := parseImports(t, want)
247247
assert.Assert(t, len(wantImports) == 1, "Expected 1 wanted import")
248-
248+
249249
gotSpec := ls.GetModuleSpecifierExpression(imports[i])
250250
wantSpec := ls.GetModuleSpecifierExpression(wantImports[0])
251-
251+
252252
if gotSpec != nil && wantSpec != nil {
253253
assert.Assert(t, ast.IsStringLiteral(gotSpec), "Expected string literal in got")
254254
assert.Assert(t, ast.IsStringLiteral(wantSpec), "Expected string literal in want")
255-
255+
256256
gotText := gotSpec.AsStringLiteral().Text
257257
wantText := wantSpec.AsStringLiteral().Text
258258
assert.Equal(t, wantText, gotText, "Import at position %d doesn't match", i)
@@ -315,10 +315,10 @@ func TestGetModuleSpecifierExpression(t *testing.T) {
315315

316316
stmt := sourceFile.Statements.Nodes[0]
317317
expr := ls.GetModuleSpecifierExpression(stmt)
318-
318+
319319
assert.Assert(t, expr != nil, "Expected non-nil module specifier")
320320
assert.Assert(t, ast.IsStringLiteral(expr), "Expected string literal")
321-
321+
322322
gotText := expr.AsStringLiteral().Text
323323
assert.Equal(t, tt.expected, gotText)
324324
})
@@ -378,4 +378,4 @@ func TestCompareImportsWithDifferentTypes(t *testing.T) {
378378
}
379379
})
380380
}
381-
}
381+
}

0 commit comments

Comments
 (0)