Skip to content

The open source coding agent.

TypeScript

feat: Add golang file formatting (#474)

Polo123456789df3b4248302f
diff --git a/packages/opencode/src/format/index.ts b/packages/opencode/src/format/index.ts
index 5ce27bc4edc..2a189380bc6 100644
--- a/packages/opencode/src/format/index.ts
+++ b/packages/opencode/src/format/index.ts
@@ -142,5 +142,24 @@ export namespace Format {
}
},
},
+ {
+ name: "gofmt",
+ command: ["gofmt", "-w", "$FILE"],
+ extensions: [".go"],
+ async enabled() {
+ try {
+ const proc = Bun.spawn({
+ cmd: ["gofmt", "-h"],
+ cwd: App.info().path.cwd,
+ stdout: "ignore",
+ stderr: "ignore",
+ })
+ const exit = await proc.exited
+ return exit === 0
+ } catch {
+ return false
+ }
+ },
+ },
]
}