aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/plugins/format.lua
blob: 561db8b192389728e21d67ebd6c032ca59d8633c (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- Verfügbare Formater: https://github.com/stevearc/conform.nvim/tree/master/lua/conform/formatters

local clang = {}
local gawk = { "gawk" } -- brew install gawk, pkg install gawk
local jq = { "jq" } -- brew install jq, pkg install jq
local prettier = { "prettier " } -- npm install -g prettier
local ruff = { "ruff_format" } -- brew install ruff, pkg install ruff
local shfmt = { "shfmt" } -- brew install shfmt, pkg install shfmt
local stylua = { "stylua" } -- brew install stylua, pkg install stylua
local xmllint = { "xmllint" } -- xmllint ist Teil von libxml2 (standardmäßig installiert unter MacOS; pkg install libxml2)
local yamlfmt = { "yamlfmt" } -- brew install yamlfmt, pkg install yamlfmt

return {
  "stevearc/conform.nvim",
  event = { "BufReadPre", "BufNewFile" },
  keys = {
    {
      "<leader>cf",
      function()
        require("conform").format({ async = true })
      end,
      desc = "Format file",
    },
  },
  opts = {
    formatters_by_ft = {
      awk = gawk,
      bash = shfmt,
      c = clang,
      cpp = clang,
      html = prettier,
      javascript = prettier,
      json = jq,
      lua = stylua,
      python = ruff,
      sh = shfmt,
      typescript = prettier,
      xml = xmllint,
      xsd = xmllint,
      yaml = yamlfmt,
    },
    default_format_opts = {
      lsp_format = "fallback",
    },
  },
}