Skip to content

Commit

Permalink
Add full support for biome (#4705)
Browse files Browse the repository at this point in the history
* Revert "Add biome support for javascript (#4701)"

This reverts commit 8922478.

* Add support for biome
  • Loading branch information
toxeus committed Feb 24, 2024
1 parent b74cd02 commit 9cc8383
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 79 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 <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'),
\})
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 <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'),
\})
10 changes: 5 additions & 5 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 Expand Up @@ -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.
Expand Down
15 changes: 4 additions & 11 deletions autoload/ale/fixers/biome.vim
Original file line number Diff line number Diff line change
@@ -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
33 changes: 25 additions & 8 deletions autoload/ale/handlers/biome.vim
Original file line number Diff line number Diff line change
@@ -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
23 changes: 1 addition & 22 deletions doc/ale-javascript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|.


===============================================================================
Expand Down
21 changes: 20 additions & 1 deletion doc/ale-typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|


===============================================================================
Expand Down
4 changes: 2 additions & 2 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down Expand Up @@ -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/)
Expand Down
30 changes: 0 additions & 30 deletions test/fixers/test_biome_fixer_callback.vader

This file was deleted.

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'
Empty file.
Empty file removed test/test-files/biome/src/test.js
Empty file.

0 comments on commit 9cc8383

Please sign in to comment.