diff options
author | Fredrik Foss-Indrehus <fredrikfoss@fr.urbanpets.no> | 2024-06-09 22:09:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-09 16:09:58 -0400 |
commit | cf562dd160c27a7fc5342dfce7e1227746dd3aaa (patch) | |
tree | bc8277bcd3b314045bf6e13666ada450fe692b6e | |
parent | 5541c54cf2ab078a537838e1fb9d96ae47f71255 (diff) |
feat: add support for for vsg (#451)
* feat: add support for vsg
* support more config files, use ctx.dirname
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | doc/conform.txt | 1 | ||||
-rw-r--r-- | lua/conform/formatters/vsg.lua | 52 |
3 files changed, 54 insertions, 0 deletions
@@ -335,6 +335,7 @@ You can view this list in vim with `:help conform-formatters` - [uncrustify](https://github.com/uncrustify/uncrustify) - A source code beautifier for C, C++, C#, ObjectiveC, D, Java, Pawn and Vala. - [usort](https://github.com/facebook/usort) - Safe, minimal import sorting for Python projects. - [verible](https://github.com/chipsalliance/verible/blob/master/verilog/tools/formatter/README.md) - The SystemVerilog formatter. +- [vsg](https://github.com/jeremiah-c-leary/vhdl-style-guide) - Style guide enforcement for VHDL. - [xmlformat](https://github.com/pamoller/xmlformatter) - xmlformatter is an Open Source Python package, which provides formatting of XML documents. - [xmllint](http://xmlsoft.org/xmllint.html) - Despite the name, xmllint can be used to format XML files as well as lint them. - [yamlfix](https://github.com/lyz-code/yamlfix) - A configurable YAML formatter that keeps comments. diff --git a/doc/conform.txt b/doc/conform.txt index 6b077fe..03d97b4 100644 --- a/doc/conform.txt +++ b/doc/conform.txt @@ -413,6 +413,7 @@ FORMATTERS *conform-formatter Pawn and Vala. `usort` - Safe, minimal import sorting for Python projects. `verible` - The SystemVerilog formatter. +`vsg` - Style guide enforcement for VHDL. `xmlformat` - xmlformatter is an Open Source Python package, which provides formatting of XML documents. `xmllint` - Despite the name, xmllint can be used to format XML files as well as 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, +} |