Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(biome): find root when using biome.jsonc #4774

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions autoload/ale/handlers/biome.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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)
call ale#Set('biome_lsp_project_root', '')

function! ale#handlers#biome#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'biome', [
Expand All @@ -30,7 +31,35 @@ function! ale#handlers#biome#GetLanguage(buffer) abort
endfunction

function! ale#handlers#biome#GetProjectRoot(buffer) abort
let l:biome_file = ale#path#FindNearestFile(a:buffer, 'biome.json')
let l:project_root = ale#Var(a:buffer, 'biome_lsp_project_root')

return !empty(l:biome_file) ? fnamemodify(l:biome_file, ':h') : ''
if !empty(l:project_root)
return l:project_root
endif

let l:possible_project_roots = [
\ 'biome.json',
\ 'biome.jsonc',
\ 'package.json',
\ '.git',
\ bufname(a:buffer),
\]

for l:possible_root in l:possible_project_roots
let l:project_root = ale#path#FindNearestFile(a:buffer, l:possible_root)

if empty(l:project_root)
let l:project_root = ale#path#FindNearestDirectory(a:buffer, l:possible_root)
endif

if !empty(l:project_root)
" dir:p expands to /full/path/to/dir/ whereas
" file:p expands to /full/path/to/file (no trailing slash)
" Appending '/' ensures that :h:h removes the path's last segment
" regardless of whether it is a directory or not.
return fnamemodify(l:project_root . '/', ':p:h:h')
endif
endfor

return ''
endfunction
16 changes: 16 additions & 0 deletions doc/ale-typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ g:ale_biome_fixer_apply_unsafe *g:ale_biome_fixer_apply_unsafe*
If set to `1`, biome will apply unsafe fixes along with safe fixes.


g:ale_biome_lsp_project_root *g:ale_biome_lsp_project_root*
*b:ale_biome_lsp_project_root*
Type: |String|
Default: `''`

If this variable is left unset, ALE will try to find the project root by
executing the following steps in the given order:

1. Find an ancestor directory containing a biome.json.
2. Find an ancestor directory containing a biome.jsonc.
3. Find an ancestor directory containing a package.json.
4. Find an ancestor directory containing a .git folder.
5. Use the directory of the current buffer (if the buffer was opened from
a file).


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

Expand Down
19 changes: 19 additions & 0 deletions test/linter/test_biome.vader
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Before:
Save g:ale_biome_options
Save g:ale_biome_lsp_project_root

let g:ale_biome_options = ''
let g:ale_biome_lsp_project_root = ''

call ale#assert#SetUpLinterTest('typescript', 'biome')
call ale#test#SetFilename('test.ts')
Expand Down Expand Up @@ -33,3 +35,20 @@ Execute(Uses the filetype as the language):
call ale#test#SetFilename('test.jsx')
set filetype=javascriptreact
AssertLSPLanguage 'javascriptreact'

Execute(Should find project root containing biome.json):
call ale#test#SetFilename('../test-files/biome/json/src/test.ts')

AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/biome/json')

Execute(Should find project root containing biome.jsonc):
call ale#test#SetFilename('../test-files/biome/jsonc/src/test.ts')

AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/biome/jsonc')

Execute(Should use user-specified project root):
let g:ale_biome_lsp_project_root = '/'

call ale#test#SetFilename('../test-files/biome/jsonc/src/test.ts')

AssertLSPProject '/'
2 changes: 2 additions & 0 deletions test/linter/test_typescript_deno_lsp.vader
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Before:
Save g:ale_deno_import_map
Save g:ale_deno_importMap
Save g:ale_deno_unstable
Save g:ale_deno_executable
Save g:ale_deno_lsp_project_root

let g:ale_deno_import_map = 'import_map.json'
let g:ale_deno_importMap = ''
let g:ale_deno_unstable = 0
let g:ale_deno_executable = 'deno'
let g:ale_deno_lsp_project_root = ''
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.