From 7c12d105dc14d55db9496ac0a91812bdb25e196e Mon Sep 17 00:00:00 2001 From: dragove Date: Thu, 8 Aug 2024 01:33:33 +0800 Subject: [PATCH] feat: add biome as formatter --- README.md | 1 + lua/guard-collection/formatter.lua | 7 +++++++ test/formatter/biome_spec.lua | 32 ++++++++++++++++++++++++++++++ test/setup.sh | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/formatter/biome_spec.lua diff --git a/README.md b/README.md index ae4f130..474b270 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index 65ea523..3444132 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -266,4 +266,11 @@ M.zigfmt = { stdin = true, } +M.biome = { + cmd = 'biome', + args = { 'format', '--write' }, + fname = true, + stdin = false, +} + return M diff --git a/test/formatter/biome_spec.lua b/test/formatter/biome_spec.lua new file mode 100644 index 0000000..7bd0cbd --- /dev/null +++ b/test/formatter/biome_spec.lua @@ -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) diff --git a/test/setup.sh b/test/setup.sh index b52d8df..5e6c48d 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -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 &