Skip to content

Commit

Permalink
fix(biome): run all enabled biome fixers
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 committed Apr 24, 2024
1 parent adee52f commit 608cc76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion autoload/ale/fixers/biome.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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 = '--apply'

let l:unsafe = ale#Var(a:buffer, 'biome_fixer_apply_unsafe')
if (l:unsafe is 1 || l:unsafe is v:true)
let l:apply = '--apply-unsafe'
endif

return {
\ 'command': ale#Escape(l:executable) . ' format'
\ 'command': ale#Escape(l:executable) . ' check ' . l:apply
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-file-path=%s',
\}
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
11 changes: 10 additions & 1 deletion test/fixers/test_biome_fixer_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Execute(The default biome command should be correct):
AssertFixer
\ {
\ 'command': ale#Escape('biome')
\ . ' format --stdin-file-path=%s'
\ . ' check --apply --stdin-file-path=%s'
\ }

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
\ {
\ 'command': ale#Escape('biome')
\ . ' check --apply-unsafe --stdin-file-path=%s'
\ }

0 comments on commit 608cc76

Please sign in to comment.