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"