aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/plugins/format.lua
blob: 90106572cf18f6500fe2f8d718068401f5e1bf77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
return {
  "stevearc/conform.nvim",
  event = { "BufReadPre", "BufNewFile" },
  keys = {
    {
      "<leader>cf",
      function()
        require("conform").format({
          async = true,
          lsp_fallback = true,
        })
      end,
      desc = "Format file",
    },
  },
  opts = {
    formatters_by_ft = {
      sh = { "shfmt" },                    -- brew install, pkg install shfmt
      bash = { "shfmt" },
      python = { "ruff_format", "black" }, -- brew install ruff, pkg install ruff
      lua = { "stylua" },                  -- brew install stylua, pkg install stylua
      typescript = { "prettierd", "prettier" },
      javascript = { "prettierd", "prettier" },
      json = { "jq" }, -- brew install jq, pkg install jq
      -- cpp  = { "clang_format" },
    },
  },

  config = function(_, opts)
    require("conform").setup(opts)
  end,
}