dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

formatting.lua (1711B)


      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       stylua = {
     34         inherit = true,
     35         append_args = { "--indent-width", "2", "--indent-type", "Spaces" },
     36       },
     37     },
     38     formatters_by_ft = {
     39       rust = { "rustfmt", lsp_format = "fallback" },
     40       ruby = { "rubyfmt", lsp_format = "fallback" },
     41       python = { "ruff_format", "ruff_organize_imports", lsp_format = "fallback" },
     42       lua = { "stylua" },
     43       -- python = { "black", lsp_format = "fallback" },
     44       --   -- lua = { 'stylua' },
     45       --   -- Conform can also run multiple formatters sequentially
     46       --   -- python = { "isort", "black" },
     47       --   --
     48       --   -- You can use 'stop_after_first' to run the first available formatter from the list
     49       --   -- javascript = { "prettierd", "prettier", stop_after_first = true },
     50     },
     51   },
     52 }