conform.nvim icon indicating copy to clipboard operation
conform.nvim copied to clipboard

[question] update formaters_by_ft at "runtime"?

Open melMass opened this issue 8 months ago • 3 comments

Hi,

I'm working on a project that uses a different tooling stack than I do (prettier instead of biome etc etc..) And I'm relying on exrc (.nvim.lua) for project specific settings but I can't find how to configure conform from there, the following doesn't properly update:

./.nvim.lua

local conform = require("conform")

-- NOTE: I INITIALLY TRIED THAT TOO:
-- conform.setup({
-- 	formatters_by_ft = {
-- 		javascript = { "prettier" },
-- 		typescript = { "prettier" },
-- 		json = { "prettier" },
-- 		jsonc = { "prettier" },
-- 		jsx = { "prettier" },
-- 		tsx = { "prettier" },
-- 		css = { "prettier" },
-- 		markdown = { "prettier" },
-- 	},
-- })

conform.formatters_by_ft.tsx = { "prettier" }
conform.formatters_by_ft.typescript = { "prettier" }
conform.formatters_by_ft.javascript = { "prettier" }
conform.formatters_by_ft.json = { "prettier" }

I'm sure it's obvious and have been talked about before but I couldn't find it, hopefully I used keywords that will help others in my situation

melMass avatar Apr 08 '25 11:04 melMass

That should definitely work. When you get to the situation where you're in a project and it's using the wrong formatters, can you do :=require("conform").formatters_by_ft and confirm that the value of that table has actually been updated?

stevearc avatar Apr 20 '25 20:04 stevearc

My bad I was on other projects, I'm back on the culprit project so I'll provide a proper log / debug / reproduction tonight

melMass avatar May 07 '25 18:05 melMass

@melMass I use .lazy.lua and also encountered the same problem. Finally I found the following way works:

-- /path/to/your/project/.lazy.lua
return {
	"stevearc/conform.nvim",
	opts = {
		formatters_by_ft = {
			go = { "goimports" },
		},
	},
}

wfxr avatar Jul 31 '25 06:07 wfxr