diff --git a/packages/opencode/src/format/formatter.ts b/packages/opencode/src/format/formatter.ts index cf68944a330..bbdd46f8789 100644 --- a/packages/opencode/src/format/formatter.ts +++ b/packages/opencode/src/format/formatter.ts @@ -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 + }, +} \ No newline at end of file diff --git a/packages/web/src/content/docs/formatters.mdx b/packages/web/src/content/docs/formatters.mdx index b49ec71c307..262301ade94 100644 --- a/packages/web/src/content/docs/formatters.mdx +++ b/packages/web/src/content/docs/formatters.mdx @@ -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.