Skip to content

Commit

Permalink
fix(biome): run all enabled biome fixers (dense-analysis#4763)
Browse files Browse the repository at this point in the history
- based on biome config, will format, lint, and/or sort imports
- adds variable to apply unsafe fixes, disabled by default

fixes: dense-analysis#4754
  • Loading branch information
redbmk authored Jun 21, 2024
1 parent 0cd64c8 commit f2aef2f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion autoload/ale/fixers/biome.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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')
let l:apply = ale#Var(a:buffer, 'biome_fixer_apply_unsafe') ? '--apply-unsafe' : '--apply'

return {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape(l:executable) . ' format'
\ 'command': ale#Escape(l:executable) . ' check ' . l:apply
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' %t'
\}
Expand Down
1 change: 1 addition & 0 deletions autoload/ale/handlers/biome.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
call ale#Set('biome_executable', 'biome')
call ale#Set('biome_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('biome_options', '')
call ale#Set('biome_fixer_apply_unsafe', 0)

function! ale#handlers#biome#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'biome', [
Expand Down
8 changes: 8 additions & 0 deletions doc/ale-typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ g:ale_biome_use_global *g:ale_biome_use_global*
See |ale-integrations-local-executables|


g:ale_biome_fixer_apply_unsafe *g:ale_biome_fixer_apply_unsafe*
*b:ale_biome_fixer_apply_unsafe*
Type: |Number|
Default: `0`

If set to `1`, biome will apply unsafe fixes along with safe fixes.


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

Expand Down
18 changes: 17 additions & 1 deletion test/fixers/test_biome_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Before:
Save g:ale_biome_options
Save g:ale_biome_fixer_apply_unsafe

let g:ale_biome_options = ''
let g:ale_biome_fixer_apply_unsafe = 0

call ale#assert#SetUpFixerTest('typescript', 'biome')

After:
Expand All @@ -11,6 +17,16 @@ Execute(The default biome command should be correct):
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('biome')
\ . ' format %t'
\ . ' check --apply %t'
\ }

Execute(Unsafe fixes can be applied via an option):
call ale#test#SetFilename('../test-files/typescript/test.ts')
let g:ale_biome_fixer_apply_unsafe = 1

AssertFixer
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('biome')
\ . ' check --apply-unsafe %t'
\ }
6 changes: 5 additions & 1 deletion test/linter/test_typescript_biome.vader
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Before:
Save g:ale_biome_options

let g:ale_biome_options = ''

call ale#assert#SetUpLinterTest('typescript', 'biome')
call ale#test#SetFilename('test.ts')

Expand All @@ -9,6 +13,6 @@ 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'
let g:ale_biome_options = '--foobar'

AssertLinter 'biome', ale#Escape('biome') . ' lsp-proxy --foobar'

0 comments on commit f2aef2f

Please sign in to comment.