formatting.lua (1584B)
1 -- Autoformat 2 return { 3 'stevearc/conform.nvim', 4 event = { 'BufWritePre' }, 5 cmd = { 'ConformInfo' }, 6 keys = { 7 { 8 'gQ', 9 function() 10 require('conform').format { async = true, lsp_fallback = true } 11 end, 12 mode = '', 13 desc = '[F]ormat buffer', 14 }, 15 }, 16 opts = { 17 notify_on_error = false, 18 format_on_save = function(bufnr) 19 -- Disable "format_on_save lsp_fallback" for languages that don't 20 -- have a well standardized coding style. You can add additional 21 -- languages here or re-enable it for the disabled ones. 22 local disable_filetypes = { c = true, cpp = true } 23 return { 24 timeout_ms = 500, 25 lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], 26 } 27 end, 28 formatters = { 29 ruff_format = { 30 inherit = true, 31 append_args = { "--config", "~/Documents/cdmi/automation/meta-files/ruff.toml" }, 32 }, 33 }, 34 formatters_by_ft = { 35 rust = { "rustfmt", lsp_format = "fallback" }, 36 ruby = { "rubyfmt", lsp_format = "fallback" }, 37 python = { "ruff_format", "ruff_organize_imports", lsp_format = "fallback" }, 38 lua = { "stylua" }, 39 -- python = { "black", lsp_format = "fallback" }, 40 -- -- lua = { 'stylua' }, 41 -- -- Conform can also run multiple formatters sequentially 42 -- -- python = { "isort", "black" }, 43 -- -- 44 -- -- You can use 'stop_after_first' to run the first available formatter from the list 45 -- -- javascript = { "prettierd", "prettier", stop_after_first = true }, 46 }, 47 }, 48 }