From 60b3dbfed305d3bc929995f39ff42a753c80d84a Mon Sep 17 00:00:00 2001 From: Emmet Murray Date: Fri, 4 Oct 2024 10:57:08 -0600 Subject: [PATCH] feat: swiftformat. --- README.md | 2 +- lua/guard-collection/formatter.lua | 2 ++ test/formatter/swiftformat.lua | 18 ++++++++++++++++++ test/setup.sh | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/formatter/swiftformat.lua diff --git a/README.md b/README.md index 474b270..090214d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ - [x] [taplo](https://github.com/tamasfe/taplo) - [ ] [shfmt](https://github.com/mvdan/sh) - [x] [stylua](https://github.com/JohnnyMorganz/StyLua) -- [ ] [swiftformat](https://github.com/nicklockwood/SwiftFormat) +- [x] [swiftformat](https://github.com/nicklockwood/SwiftFormat) - [ ] [swift-format](https://github.com/apple/swift-format) - [ ] [sqlfluff](https://github.com/sqlfluff/sqlfluff) as `sqlfluff format` - [x] [sqlfluff_fix](https://github.com/sqlfluff/sqlfluff) as `sqlfluff fix` diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index 3444132..962a510 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -216,7 +216,9 @@ M.stylua = { M.swiftformat = { cmd = 'swiftformat', + args = { '--stdinpath' }, stdin = true, + fname = true, } M['swift-format'] = { diff --git a/test/formatter/swiftformat.lua b/test/formatter/swiftformat.lua new file mode 100644 index 0000000..c8e0f55 --- /dev/null +++ b/test/formatter/swiftformat.lua @@ -0,0 +1,18 @@ +describe('swiftformat', function() + it('can format', function() + local ft = require('guard.filetype') + ft('swift'):fmt('swiftformat') + require('guard').setup() + + local formatted = require('test.formatter.helper').test_with('swift', { + [[func myFunc() { ]], + [[print("hello") ]], + [[ }]], + }) + assert.are.same({ + [[func myFunc() {]], + [[ print("hello")]], + [[}]], + }, formatted) + end) +end) diff --git a/test/setup.sh b/test/setup.sh index 5e6c48d..ab86126 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -9,7 +9,7 @@ pip -qqq install autopep8 black djhtml docformatter flake8 isort pylint yapf cod npm install -g --silent \ prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli @biomejs/biome & brew install \ - hlint ormolu clang-format golines gofumpt detekt & + hlint ormolu clang-format golines gofumpt detekt swiftformat & # Install standalone binary packages bin="$HOME/.local/bin"