Add biome support for javascript (#4701)

This commit is contained in:
Akiomi Kamakura 2024-01-14 21:11:14 +09:00 committed by GitHub
parent 531970533a
commit 8922478a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 105 additions and 0 deletions

View File

@ -646,6 +646,11 @@ 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

@ -0,0 +1,17 @@
" 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')
return {
\ 'command': (has('win32') ? (ale#Escape(l:node) . ' ') : '')
\ . ale#Escape(l:executable)
\ . ' check --apply'
\ . ale#Pad(l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -0,0 +1,14 @@
" Author: Akiomi Kamakura <akiomik@gmail.com>
" Description: Functions for working with biome, for 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', '')
function! ale#handlers#biome#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'javascript_biome', [
\ 'node_modules/.bin/biome',
\ 'node_modules/@biomejs/biome/bin/biome',
\])
endfunction

View File

@ -25,6 +25,33 @@ 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.
===============================================================================
clang-format *ale-javascript-clangformat*

View File

@ -292,6 +292,7 @@ Notes:
* `javalsp`
* `uncrustify`
* JavaScript
* `biome`
* `clang-format`
* `cspell`
* `deno`
@ -653,6 +654,7 @@ Notes:
* TOML
* `dprint`
* TypeScript
* `biome`
* `cspell`
* `deno`
* `dprint`

View File

@ -2,6 +2,12 @@
ALE TypeScript Integration *ale-typescript-options*
===============================================================================
biome *ale-typescript-biome*
See |ale-javascript-biome|
===============================================================================
cspell *ale-typescript-cspell*

View File

@ -3116,6 +3116,7 @@ documented in additional help files.
eclipselsp............................|ale-java-eclipselsp|
uncrustify............................|ale-java-uncrustify|
javascript..............................|ale-javascript-options|
biome.................................|ale-javascript-biome|
clang-format..........................|ale-javascript-clangformat|
cspell................................|ale-javascript-cspell|
deno..................................|ale-javascript-deno|
@ -3439,6 +3440,7 @@ documented in additional help files.
toml....................................|ale-toml-options|
dprint................................|ale-toml-dprint|
typescript..............................|ale-typescript-options|
biome.................................|ale-typescript-biome|
cspell................................|ale-typescript-cspell|
deno..................................|ale-typescript-deno|
dprint................................|ale-typescript-dprint|

View File

@ -301,6 +301,7 @@ formatting.
* [javalsp](https://github.com/georgewfraser/vscode-javac)
* [uncrustify](https://github.com/uncrustify/uncrustify)
* JavaScript
* [biome](http://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/)
@ -662,6 +663,7 @@ formatting.
* TOML
* [dprint](https://dprint.dev)
* TypeScript
* [biome](http://biomejs.dev)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [deno](https://deno.land/)
* [dprint](https://dprint.dev/)

View File

@ -0,0 +1,30 @@
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',
\ }

0
test/test-files/biome/node_modules/.bin/biome generated vendored Normal file
View File

View File