Find composer.json when searching for psalm (#3979)

* Look for nearest composer.json before .git

* Add test for projects with composer.json
This commit is contained in:
Daisuke Shimamoto
2021-11-15 21:17:18 +09:00
committed by GitHub
parent 01fdd8d66b
commit 31dc6a61a0
2 changed files with 11 additions and 0 deletions

View File

@@ -6,6 +6,12 @@ call ale#Set('php_psalm_options', '')
call ale#Set('php_psalm_use_global', get(g:, 'ale_use_global_executables', 0)) call ale#Set('php_psalm_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale_linters#php#psalm#GetProjectRoot(buffer) abort function! ale_linters#php#psalm#GetProjectRoot(buffer) abort
let l:composer_path = ale#path#FindNearestFile(a:buffer, 'composer.json')
if (!empty(l:composer_path))
return fnamemodify(l:composer_path, ':h')
endif
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git') let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : '' return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : ''

View File

@@ -36,3 +36,8 @@ Execute(User provided options should be used):
AssertLinter 'psalm', AssertLinter 'psalm',
\ ale#Escape('psalm') \ ale#Escape('psalm')
\ . ' --language-server --my-user-provided-option my-value' \ . ' --language-server --my-user-provided-option my-value'
Execute(The project path should be correct for composer.json file):
call ale#test#SetFilename('../test-files/php/with-composer/test.php')
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/php/with-composer')