Skip to content

Commit

Permalink
Add biome support for javascript (dense-analysis#4701)
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik authored Jan 14, 2024
1 parent 5319705 commit 8922478
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions autoload/ale/fixers/biome.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
" Author: Akiomi Kamakura <[email protected]>
" 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
14 changes: 14 additions & 0 deletions autoload/ale/handlers/biome.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
" Author: Akiomi Kamakura <[email protected]>
" 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
27 changes: 27 additions & 0 deletions doc/ale-javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
2 changes: 2 additions & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Notes:
* `javalsp`
* `uncrustify`
* JavaScript
* `biome`
* `clang-format`
* `cspell`
* `deno`
Expand Down Expand Up @@ -653,6 +654,7 @@ Notes:
* TOML
* `dprint`
* TypeScript
* `biome`
* `cspell`
* `deno`
* `dprint`
Expand Down
6 changes: 6 additions & 0 deletions doc/ale-typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
ALE TypeScript Integration *ale-typescript-options*


===============================================================================
biome *ale-typescript-biome*

See |ale-javascript-biome|


===============================================================================
cspell *ale-typescript-cspell*

Expand Down
2 changes: 2 additions & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down
2 changes: 2 additions & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down Expand Up @@ -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/)
Expand Down
30 changes: 30 additions & 0 deletions test/fixers/test_biome_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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',
\ }
Empty file.
Empty file.

0 comments on commit 8922478

Please sign in to comment.