From cf562dd160c27a7fc5342dfce7e1227746dd3aaa Mon Sep 17 00:00:00 2001 From: Fredrik Foss-Indrehus Date: Sun, 9 Jun 2024 22:09:58 +0200 Subject: feat: add support for for vsg (#451) * feat: add support for vsg * support more config files, use ctx.dirname --- lua/conform/formatters/vsg.lua | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lua/conform/formatters/vsg.lua (limited to 'lua/conform/formatters/vsg.lua') diff --git a/lua/conform/formatters/vsg.lua b/lua/conform/formatters/vsg.lua new file mode 100644 index 0000000..ca0059e --- /dev/null +++ b/lua/conform/formatters/vsg.lua @@ -0,0 +1,52 @@ +local config_files = { + "vsg_config.yaml", + "vsg_config.yml", + "vsg_config.json", + "vsg.yaml", + "vsg.yml", + "vsg.json", + ".vsg_config.yaml", + ".vsg_config.yml", + ".vsg_config.json", + ".vsg.yaml", + ".vsg.yml", + ".vsg.json", +} + +local function find_config(dirname) + local paths = { + dirname, + (os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME") .. "/.config") .. "/vsg", + } + + for _, path in ipairs(paths) do + local config = vim.fs.find(config_files, { + path = path, + upward = path == dirname, + })[1] + if config then + return config + end + end +end + +---@type conform.FileFormatterConfig +return { + meta = { + url = "https://github.com/jeremiah-c-leary/vhdl-style-guide", + description = "Style guide enforcement for VHDL.", + }, + command = "vsg", + stdin = false, + args = function(_, ctx) + local args = { "-of", "syntastic", "--fix", "-f", "$FILENAME" } + local config_file = find_config(ctx.dirname) + + if config_file then + table.insert(args, "-c") + table.insert(args, config_file) + end + + return args + end, +} -- cgit v1.2.3-70-g09d2