Skip to content

Commit

Permalink
feat: add taplo formatter (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcholla authored Oct 4, 2023
1 parent 6b95e25 commit 4083df7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [x] [prettier](https://github.com/prettier/prettier)
- [ ] [rubocop](https://github.com/rubocop/rubocop)
- [x] [rustfmt](https://github.com/rust-lang/rustfmt)
- [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)
Expand All @@ -37,7 +38,6 @@
- [x] [ruff](https://github.com/astral-sh/ruff) as `ruff format`
- [x] [ruff_fix](https://github.com/astral-sh/ruff) as `ruff --fix`


## Linters

- [x] [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
Expand Down
6 changes: 6 additions & 0 deletions lua/guard-collection/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ M.rustfmt = {
stdin = true,
}

M.taplo = {
cmd = 'taplo',
args = { 'format', '-' },
stdin = true,
}

M.shfmt = {
cmd = 'shfmt',
stdin = true,
Expand Down
24 changes: 24 additions & 0 deletions test/formatter/taplo_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('taplo', function()
it('can format', function()
local ft = require('guard.filetype')
ft('toml'):fmt('taplo')
require('guard').setup()

local formatted = require('test.formatter.helper').test_with('toml', {
[[ [dependencies] ]],
[[ async-process = "^1.7"]],
[[strum = { version = "^0.25", features = ["derive"] } ]],
[[anyhow = "1" ]],
[[tracing-error = "0.2" ]],
[[]],
[[]]
})
assert.are.same({
"[dependencies]",
[[async-process = "^1.7"]],
[[strum = { version = "^0.25", features = ["derive"] }]],
[[anyhow = "1"]],
[[tracing-error = "0.2"]],
}, formatted)
end)
end)
2 changes: 1 addition & 1 deletion test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ luarocks install luacheck &
go install github.com/segmentio/golines@latest &
pip -qqq install autopep8 black djhtml flake8 isort pylint yapf codespell ruff &
npm install -g --silent \
prettier @fsouza/prettierd sql-formatter shellcheck shfmt &
prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli &
gem install -q rubocop &
# Block, homebrew takes the longest time
brew install \
Expand Down

0 comments on commit 4083df7

Please sign in to comment.