Skip to content

Commit

Permalink
feat: add biome as formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Aug 7, 2024
1 parent de6587e commit 7c12d10
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `lsp` using `vim.lsp.buf.format`
- [x] [autopep8](https://github.com/hhatto/autopep8)
- [x] [black](https://github.com/psf/black)
- [x] [biome](https://biomejs.dev)
- [ ] [cbfmt](https://github.com/lukas-reineke/cbfmt)
- [x] [clang-format](https://www.kernel.org/doc/html/latest/process/clang-format.html)
- [ ] [csharpier](https://csharpier.com/)
Expand Down
7 changes: 7 additions & 0 deletions lua/guard-collection/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,11 @@ M.zigfmt = {
stdin = true,
}

M.biome = {
cmd = 'biome',
args = { 'format', '--write' },
fname = true,
stdin = false,
}

return M
32 changes: 32 additions & 0 deletions test/formatter/biome_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe('biome', function()
it('can format json', function()
local ft = require('guard.filetype')
ft('json'):fmt('biome')
require('guard').setup()

local formatted = require('test.formatter.helper').test_with('json', {
[[{"name": "dove" , "age":10 ]],
[[,"gender": "male"}]],
})
assert.are.same({
[[{ "name": "dove", "age": 10, "gender": "male" }]],
}, formatted)
end)

it('can format javascript', function()
local ft = require('guard.filetype')
ft('js'):fmt('biome')
require('guard').setup()

local formatted = require('test.formatter.helper').test_with('js', {
[[ const randomNumber = Math.floor(]],
[[ Math.random() * 10]],
[[ ) + 1]],
[[alert(randomNumber)]],
})
assert.are.same({
[[const randomNumber = Math.floor(Math.random() * 10) + 1;]],
[[alert(randomNumber);]],
}, formatted)
end)
end)
2 changes: 1 addition & 1 deletion test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
luarocks install luacheck &
pip -qqq install autopep8 black djhtml docformatter flake8 isort pylint yapf codespell ruff sqlfluff clang-tidy mypy &
npm install -g --silent \
prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli &
prettier @fsouza/prettierd sql-formatter shellcheck shfmt @taplo/cli @biomejs/biome &
brew install \
hlint ormolu clang-format golines gofumpt detekt &

Expand Down

0 comments on commit 7c12d10

Please sign in to comment.