Add full support for biome (#4705)

* Revert "Add biome support for javascript (#4701)"

This reverts commit 8922478a83.

* Add support for biome
This commit is contained in:
Filip Gospodinov 2024-02-24 08:51:39 +01:00 committed by GitHub
parent b74cd02648
commit 9cc8383fe9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 91 additions and 79 deletions

View File

@ -0,0 +1,10 @@
" Author: Filip Gospodinov <f@gospodinov.ch>
" Description: biome for JavaScript files
call ale#linter#Define('javascript', {
\ 'name': 'biome',
\ 'lsp': 'stdio',
\ 'executable': function('ale#handlers#biome#GetExecutable'),
\ 'command': function('ale#handlers#biome#GetCommand'),
\ 'project_root': function('ale#handlers#biome#GetProjectRoot'),
\})

View File

@ -0,0 +1,10 @@
" Author: Filip Gospodinov <f@gospodinov.ch>
" Description: biome for TypeScript files
call ale#linter#Define('typescript', {
\ 'name': 'biome',
\ 'lsp': 'stdio',
\ 'executable': function('ale#handlers#biome#GetExecutable'),
\ 'command': function('ale#handlers#biome#GetCommand'),
\ 'project_root': function('ale#handlers#biome#GetProjectRoot'),
\})

View File

@ -37,6 +37,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['bib'],
\ 'description': 'Format bib files using bibclean.',
\ },
\ 'biome': {
\ 'function': 'ale#fixers#biome#Fix',
\ 'suggested_filetypes': ['javascript', 'typescript'],
\ 'description': 'Fix JavaScript and TypeScript using biome.',
\ },
\ 'black': {
\ 'function': 'ale#fixers#black#Fix',
\ 'suggested_filetypes': ['python'],
@ -651,11 +656,6 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ruby'],
\ 'description': 'A formatter for Ruby source code',
\ },
\ 'biome': {
\ 'function': 'ale#fixers#biome#Fix',
\ 'suggested_filetypes': ['javascript', 'typescript'],
\ 'description': 'Apply biome (ex. rome) check to a file.',
\ },
\}
" Reset the function registry to the default entries.

View File

@ -1,17 +1,10 @@
" Author: Akiomi Kamakura <akiomik@gmail.com>
" Description: Fixing files with biome (ex.rome).
function! ale#fixers#biome#Fix(buffer) abort
let l:executable = ale#handlers#biome#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'javascript_biome_options')
let l:node = ale#Var(a:buffer, 'javascript_biome_node_executable')
let l:options = ale#Var(a:buffer, 'biome_options')
return {
\ 'command': (has('win32') ? (ale#Escape(l:node) . ' ') : '')
\ . ale#Escape(l:executable)
\ . ' check --apply'
\ . ale#Pad(l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\ 'command': '%e format'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-file-path=%s',
\}
endfunction

View File

@ -1,14 +1,31 @@
" Author: Akiomi Kamakura <akiomik@gmail.com>
" Description: Functions for working with biome, for fixing files.
" Author: Filip Gospodinov <f@gospodinov.ch>
" Description: Functions for working with biome, for checking or fixing files.
call ale#Set('javascript_biome_node_executable', 'node.exe')
call ale#Set('javascript_biome_executable', 'biome')
call ale#Set('javascript_biome_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('javascript_biome_options', '')
call ale#Set('biome_executable', 'biome')
call ale#Set('biome_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('biome_options', '')
function! ale#handlers#biome#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'javascript_biome', [
return ale#path#FindExecutable(a:buffer, 'biome', [
\ 'node_modules/@biomejs/cli-linux-x64/biome',
\ 'node_modules/@biomejs/cli-linux-arm64/biome',
\ 'node_modules/@biomejs/cli-win32-x64/biome.exe',
\ 'node_modules/@biomejs/cli-win32-arm64/biome.exe',
\ 'node_modules/@biomejs/cli-darwin-x64/biome',
\ 'node_modules/@biomejs/cli-darwin-arm64/biome',
\ 'node_modules/.bin/biome',
\ 'node_modules/@biomejs/biome/bin/biome',
\])
endfunction
function! ale#handlers#biome#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'biome_options')
return '%e lsp-proxy'
\ . (!empty(l:options) ? ' ' . l:options : '')
endfunction
function! ale#handlers#biome#GetProjectRoot(buffer) abort
let l:biome_file = ale#path#FindNearestFile(a:buffer, 'biome.json')
return !empty(l:biome_file) ? fnamemodify(l:biome_file, ':h') : ''
endfunction

View File

@ -28,28 +28,7 @@ To this: >
===============================================================================
biome *ale-javascript-biome*
g:ale_javascript_biome_executable *g:ale_javascript_biome_executable*
*b:ale_javascript_biome_executable*
Type: |String|
Default: `'biome'`
See |ale-integrations-local-executables|
g:ale_javascript_biome_use_global *g:ale_javascript_biome_use_global*
*b:ale_javascript_biome_use_global*
Type: |Number|
Default: `get(g:, 'ale_use_global_executables', 0)`
See |ale-integrations-local-executables|
g:ale_javascript_biome_options *g:ale_javascript_biome_options*
*b:ale_javascript_biome_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to biome.
Check the docs over at |ale-typescript-biome|.
===============================================================================

View File

@ -5,7 +5,26 @@ ALE TypeScript Integration *ale-typescript-options*
===============================================================================
biome *ale-typescript-biome*
See |ale-javascript-biome|
g:ale_biome_executable *g:ale_biome_executable*
*b:ale_biome_executable*
Type: |String|
Default: `'biome'`
g:ale_biome_options *g:ale_biome_options*
*b:ale_biome_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to biome.
g:ale_biome_use_global *g:ale_biome_use_global*
*b:ale_biome_use_global*
Type: |Number|
Default: `get(g:, 'ale_use_global_executables', 0)`
See |ale-integrations-local-executables|
===============================================================================

View File

@ -302,7 +302,7 @@ formatting.
* [javalsp](https://github.com/georgewfraser/vscode-javac)
* [uncrustify](https://github.com/uncrustify/uncrustify)
* JavaScript
* [biome](http://biomejs.dev)
* [biome](https://biomejs.dev/)
* [clang-format](https://clang.llvm.org/docs/ClangFormat.html)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [deno](https://deno.land/)
@ -666,7 +666,7 @@ formatting.
* TOML
* [dprint](https://dprint.dev)
* TypeScript
* [biome](http://biomejs.dev)
* [biome](https://biomejs.dev/)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [deno](https://deno.land/)
* [dprint](https://dprint.dev/)

View File

@ -1,30 +0,0 @@
Before:
call ale#assert#SetUpFixerTest('javascript', 'biome')
runtime autoload/ale/handlers/biome.vim
set filetype=javascript
After:
call ale#assert#TearDownFixerTest()
Execute(The biome callback should return the correct default values):
call ale#test#SetFilename('../test-files/biome/src/test.js')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/biome/node_modules/.bin/biome'))
\ . ' check --apply %t',
\ }
Execute(The biome callback should include custom biome options):
let b:ale_javascript_biome_options = '--organize-imports-enabled=true'
call ale#test#SetFilename('../test-files/biome/src/test.js')
AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': (has('win32') ? 'node.exe ' : '')
\ . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/biome/node_modules/.bin/biome'))
\ . ' check --apply --organize-imports-enabled=true %t',
\ }

View File

@ -0,0 +1,14 @@
Before:
call ale#assert#SetUpLinterTest('typescript', 'biome')
call ale#test#SetFilename('test.ts')
After:
call ale#assert#TearDownLinterTest()
Execute(The default biome command should be correct):
AssertLinter 'biome', ale#Escape('biome') . ' lsp-proxy'
Execute(The biome command should accept options):
let b:ale_biome_options = '--foobar'
AssertLinter 'biome', ale#Escape('biome') . ' lsp-proxy --foobar'

View File