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
26 changes: 26 additions & 0 deletions packages/opencode/src/format/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,29 @@ export const rustfmt: Info = {
return Bun.which("rustfmt") !== null
},
}

export const sqlfluff: Info = {
name: "sqlfluff",
command: ["sqlfluff", "format", "$FILE"],
extensions: [".sql"],
async enabled() {
if (!Bun.which("sqlfluff")) return false

const configs = [".sqlfluff", "pyproject.toml", "setup.cfg", "tox.ini", "pep8.ini"]

for (const config of configs) {
const found = await Filesystem.findUp(config, Instance.directory, Instance.worktree)
if (found.length > 0) {
const content = await Bun.file(found[0]).text()

const header = config === "pyproject.toml" ? "[tool.sqlfluff]" : "[sqlfluff]"

if (content.includes(header) && /dialect\s*=/.test(content)) {
return true
}
}
}

return false
},
}
1 change: 1 addition & 0 deletions packages/web/src/content/docs/formatters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OpenCode comes with several built-in formatters for popular languages and framew
| nixfmt | .nix | `nixfmt` command available |
| shfmt | .sh, .bash | `shfmt` command available |
| oxfmt (Experimental) | .js, .jsx, .ts, .tsx | `oxfmt` dependency in `package.json` and an [experimental env variable flag](/docs/cli/#experimental) |
| sqlfluff | .sql | `sqlfluff` command available and config file with dialect set |

So if your project has `prettier` in your `package.json`, OpenCode will automatically use it.

Expand Down