]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/plugins/conform.lua
use/op(nvim)(jj)(eagle): fix config
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / plugins / conform.lua
1 -- Lightweight yet powerful formatter plugin for Neovim
2 -- https://github.com/stevearc/conform.nvim
3 vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
4 return {
5 "conform.nvim",
6 event = { "BufWritePre" },
7 cmd = { "ConformInfo" },
8 after = function()
9 require("conform").setup({
10 -- Map of filetype to formatters
11 formatters_by_ft = {
12 elm = { "elm-format" },
13 lua = { "stylua" },
14 -- Conform will run multiple formatters sequentially
15 go = { "goimports", "gofmt" },
16 haskell = { "fourmolu" },
17 nix = { "nixfmt" },
18 -- You can also customize some of the format options for the filetype
19 rust = { "rustfmt", lsp_format = "fallback" },
20 -- You can use a function here to determine the formatters dynamically
21 python = function(bufnr)
22 if require("conform").get_formatter_info("ruff_format", bufnr).available then
23 return { "ruff_format" }
24 else
25 return { "isort", "black" }
26 end
27 end,
28 sh = { "shfmt" },
29 -- Use the "*" filetype to run formatters on all filetypes.
30 ["*"] = { "codespell" },
31 -- Use the "_" filetype to run formatters on filetypes that don't
32 -- have other formatters configured.
33 ["_"] = { "trim_whitespace" },
34 },
35 -- Set this to change the default values when calling conform.format()
36 -- This will also affect the default values for format_on_save/format_after_save
37 default_format_opts = {
38 lsp_format = "fallback",
39 },
40 -- If this is set, Conform will run the formatter on save.
41 -- It will pass the table to conform.format().
42 -- This can also be a function that returns the table.
43 format_after_save = function()
44 if not vim.g.formatsave or vim.b.disableFormatSave then
45 return
46 else
47 return { lsp_format = "fallback" }
48 end
49 end,
50 format_on_save = function()
51 if not vim.g.formatsave or vim.b.disableFormatSave then
52 return
53 else
54 return { lsp_format = "fallback", timeout_ms = 500 }
55 end
56 end,
57 -- Set the log level. Use `:ConformInfo` to see the location of the log file.
58 log_level = vim.log.levels.ERROR,
59 -- Conform will notify you when a formatter errors
60 notify_on_error = true,
61 -- Conform will notify you when no formatters are available for the buffer
62 notify_no_formatters = true,
63 -- Custom formatters and overrides for built-in formatters
64 formatters = {},
65 })
66 end,
67 }