Skip to content

Commit

Permalink
Add support for biome
Browse files Browse the repository at this point in the history
  • Loading branch information
toxeus committed Feb 23, 2024
1 parent db64d7c commit 40277ed
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ale_linters/javascript/biome.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" Author: Filip Gospodinov <[email protected]>
" 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'),
\})
10 changes: 10 additions & 0 deletions ale_linters/typescript/biome.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" Author: Filip Gospodinov <[email protected]>
" 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'),
\})
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
10 changes: 10 additions & 0 deletions autoload/ale/fixers/biome.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function! ale#fixers#biome#Fix(buffer) abort
let l:executable = ale#handlers#biome#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'biome_options')

return {
\ 'command': '%e format'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-file-path=%s',
\}
endfunction
31 changes: 31 additions & 0 deletions autoload/ale/handlers/biome.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
" Author: Filip Gospodinov <[email protected]>
" Description: Functions for working with biome, for checking or fixing files.

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, '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',
\])
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
6 changes: 6 additions & 0 deletions doc/ale-javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ To this: >
<


===============================================================================
biome *ale-javascript-biome*

Check the docs over at |ale-typescript-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
25 changes: 25 additions & 0 deletions doc/ale-typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@
ALE TypeScript Integration *ale-typescript-options*


===============================================================================
biome *ale-typescript-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|


===============================================================================
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](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/)
Expand Down Expand Up @@ -662,6 +663,7 @@ formatting.
* TOML
* [dprint](https://dprint.dev)
* TypeScript
* [biome](https://biomejs.dev/)
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
* [deno](https://deno.land/)
* [dprint](https://dprint.dev/)
Expand Down
14 changes: 14 additions & 0 deletions test/linter/test_typescript_biome.vader
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 40277ed

Please sign in to comment.