From a598713f1f6ffcdf3ca85b97adfe79700ef4edf5 Mon Sep 17 00:00:00 2001 From: joelazar Date: Fri, 24 Apr 2026 16:13:45 +0200 Subject: [PATCH] :wrench: refactor conform.nvim to make prettier yield to biome - Refactor opts from static object to function that extends defaults - Add has_biome_config() helper to detect biome config files - Wrap prettier condition to skip when biome.json exists - Use vim.tbl_deep_extend for formatters_by_ft to merge with LazyVim extras - Preserve sqlfluff, mojo, and shfmt formatter configurations --- lua/plugins/conform.lua | 62 ++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index e087331..ae5bacc 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -1,28 +1,52 @@ -- Code formatting configuration -- Sets up formatters for SQL and Mojo languages +-- Biome/Prettier for JS/TS handled by LazyVim extras: +-- lazyvim.plugins.extras.lang.typescript.biome +-- lazyvim.plugins.extras.formatting.prettier +-- This config also makes prettier yield to biome when a biome config is present, +-- so a global ~/.prettierrc doesn't clobber biome-formatted output. +local function has_biome_config(ctx) + return vim.fs.root(ctx.dirname, { "biome.json", "biome.jsonc", ".biome.json", ".biome.jsonc" }) ~= nil +end + return { "stevearc/conform.nvim", - opts = { - formatters_by_ft = { + opts = function(_, opts) + opts.formatters_by_ft = vim.tbl_deep_extend("force", opts.formatters_by_ft or {}, { mojo = { "mojo" }, sql = { "sqlfluff" }, mysql = { "sqlfluff" }, plsql = { "sqlfluff" }, - }, - formatters = { - sqlfluff = { - require_cwd = false, - args = { "format", "--config", os.getenv("HOME") .. "/.config/nvim/.sqlfluff", "-" }, - }, - mojo = { - inherit = false, - command = "mojo", - args = { "format", "--quiet", "$FILENAME" }, - stdin = false, - }, - shfmt = { - args = { "-i", "4" }, - }, - }, - }, + }) + + opts.formatters = opts.formatters or {} + + -- Wrap prettier condition from LazyVim's prettier extra: also skip when biome config exists. + local prettier = opts.formatters.prettier or {} + local prev_cond = prettier.condition + prettier.condition = function(self, ctx) + if has_biome_config(ctx) then + return false + end + if prev_cond then + return prev_cond(self, ctx) + end + return true + end + opts.formatters.prettier = prettier + + opts.formatters.sqlfluff = { + require_cwd = false, + args = { "format", "--config", os.getenv("HOME") .. "/.config/nvim/.sqlfluff", "-" }, + } + opts.formatters.mojo = { + inherit = false, + command = "mojo", + args = { "format", "--quiet", "$FILENAME" }, + stdin = false, + } + opts.formatters.shfmt = { + args = { "-i", "4" }, + } + end, } -- 2.51.2