From 8c43ebd619d724133e1063e3b686907d5aa56abe Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Mon, 7 Sep 2026 16:14:59 +0200 Subject: Unterstützung für jsonc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nvim/lua/plugins/format.lua | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'nvim/lua') diff --git a/nvim/lua/plugins/format.lua b/nvim/lua/plugins/format.lua index 714e887..476e513 100644 --- a/nvim/lua/plugins/format.lua +++ b/nvim/lua/plugins/format.lua @@ -5,21 +5,13 @@ local djlint = { "djlint" } -- pipx install djlint (macOS & FreeBSD); unter Wind 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 prettier_jsonc = { "prettier_jsonc" } -- prettier-Variante, konfiguriert unter opts.formatters 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 --- prettier leitet den Parser aus dem Dateinamen ab: .json landet beim strikten --- json-Parser, der Kommentare ablehnt. Im Filetype jsonc erzwingen wir deshalb --- den kommentartoleranten jsonc-Parser (prettier >= 3.0). -local function prettier_parser_args(_, ctx) - if vim.bo[ctx.buf].filetype == "jsonc" then return { "--parser", "jsonc" } end - - return {} -end - return { "stevearc/conform.nvim", event = { "BufReadPre", "BufNewFile" }, @@ -42,7 +34,7 @@ return { javascript = prettier, jinja = djlint, json = jq, - jsonc = prettier, + jsonc = prettier_jsonc, lua = stylua, python = ruff, sh = shfmt, @@ -52,8 +44,9 @@ return { yaml = yamlfmt, }, formatters = { - prettier = { - prepend_args = prettier_parser_args, + prettier_jsonc = { + inherit = "prettier", + prepend_args = { "--parser", "jsonc" }, }, }, default_format_opts = { -- cgit v1.3