Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions packages/opencode/src/format/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,54 @@ export const dfmt: Info = {
return [match, "-i", "$FILE"]
},
}

export const stylua: Info = {
name: "stylua",
extensions: [".lua"],
async enabled() {
const match = which("stylua")
if (!match) return false
return [match, "$FILE"]
},
}

export const swiftformat: Info = {
name: "swiftformat",
extensions: [".swift"],
async enabled() {
const match = which("swiftformat")
if (!match) return false
return [match, "$FILE"]
},
}

export const scalafmt: Info = {
name: "scalafmt",
extensions: [".scala"],
async enabled(context) {
if (!which("scalafmt")) return false
const items = await Filesystem.findUp(".scalafmt.conf", context.directory, context.worktree)
if (items.length > 0) return ["scalafmt", "$FILE"]
return false
},
}

export const typstfmt: Info = {
name: "typst",
extensions: [".typ", ".typc"],
async enabled() {
const match = which("typst")
if (!match) return false
return [match, "fmt", "$FILE"]
},
}

export const csharpier: Info = {
name: "csharpier",
extensions: [".cs"],
async enabled() {
const match = which("dotnet-csharpier")
if (!match) return false
return [match, "$FILE"]
},
}
5 changes: 5 additions & 0 deletions packages/web/src/content/docs/formatters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OpenCode comes with several built-in formatters for popular languages and framew
| cargofmt | .rs | `cargo fmt` command available |
| clang-format | .c, .cpp, .h, .hpp, .ino, and [more](https://clang.llvm.org/docs/ClangFormat.html) | `.clang-format` config file |
| cljfmt | .clj, .cljs, .cljc, .edn | `cljfmt` command available |
| csharpier | .cs | `dotnet-csharpier` command available |
| dart | .dart | `dart` command available |
| dfmt | .d | `dfmt` command available |
| gleam | .gleam | `gleam` command available |
Expand All @@ -34,9 +35,13 @@ OpenCode comes with several built-in formatters for popular languages and framew
| rubocop | .rb, .rake, .gemspec, .ru | `rubocop` command available |
| ruff | .py, .pyi | `ruff` command available with config |
| rustfmt | .rs | `rustfmt` command available |
| scalafmt | .scala | `scalafmt` command available and `.scalafmt.conf` config file |
| shfmt | .sh, .bash | `shfmt` command available |
| standardrb | .rb, .rake, .gemspec, .ru | `standardrb` command available |
| stylua | .lua | `stylua` command available |
| swiftformat | .swift | `swiftformat` command available |
| terraform | .tf, .tfvars | `terraform` command available |
| typst | .typ, .typc | `typst` command available |
| uv | .py, .pyi | `uv` command available |
| zig | .zig, .zon | `zig` command available |

Expand Down
Loading