All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: medains <https://github.com/medains>, ardis <https://github.com/ardisdreelath>, Arizard <https://github.com/Arizard>
2 " Description: phpstan for PHP files
4 " Set to change the ruleset
5 let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpstan')
6 let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '')
7 let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '')
8 let g:ale_php_phpstan_autoload = get(g:, 'ale_php_phpstan_autoload', '')
9 let g:ale_php_phpstan_memory_limit = get(g:, 'ale_php_phpstan_memory_limit', '')
10 call ale#Set('php_phpstan_use_global', get(g:, 'ale_use_global_executables', 0))
12 function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
13 let l:configuration = ale#Var(a:buffer, 'php_phpstan_configuration')
14 let l:configuration_option = !empty(l:configuration)
15 \ ? ' -c ' . ale#Escape(l:configuration)
18 let l:autoload = ale#Var(a:buffer, 'php_phpstan_autoload')
19 let l:autoload_option = !empty(l:autoload)
20 \ ? ' -a ' . ale#Escape(l:autoload)
23 let l:memory_limit = ale#Var(a:buffer, 'php_phpstan_memory_limit')
24 let l:memory_limit_option = !empty(l:memory_limit)
25 \ ? ' --memory-limit=' . ale#Escape(l:memory_limit)
28 let l:level = ale#Var(a:buffer, 'php_phpstan_level')
30 if empty(l:level) && empty(ale_linters#php#phpstan#FindConfigFile(a:buffer))
31 " if no configuration file is found, then use 4 as a default level
35 let l:level_option = !empty(l:level)
36 \ ? ' -l ' . ale#Escape(l:level)
39 let l:error_format = ale#semver#GTE(a:version, [0, 10, 3])
40 \ ? ' --error-format json'
41 \ : ' --errorFormat json'
43 return '%e analyze --no-progress'
45 \ . l:configuration_option
48 \ . l:memory_limit_option
52 function! ale_linters#php#phpstan#Handle(buffer, lines) abort
53 let l:res = ale#util#FuzzyJSONDecode(a:lines, {'files': []})
56 if type(l:res.files) is v:t_list
60 for l:key in keys(l:res.files)
61 for l:err in l:res.files[l:key].messages
64 \ 'text': l:err.message,
73 function! ale_linters#php#phpstan#GetCwd(buffer) abort
74 let l:result = ale#path#Dirname(ale_linters#php#phpstan#FindConfigFile(a:buffer))
76 return empty(l:result) ? v:null : l:result
79 function! ale_linters#php#phpstan#FindConfigFile(buffer) abort
80 let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.neon')
83 let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.neon.dist')
89 call ale#linter#Define('php', {
91 \ 'executable': {buffer -> ale#path#FindExecutable(buffer, 'php_phpstan', [
92 \ 'vendor/bin/phpstan',
95 \ 'command': {buffer -> ale#semver#RunWithVersionCheck(
97 \ ale#path#FindExecutable(buffer, 'php_phpstan', [
98 \ 'vendor/bin/phpstan',
102 \ function('ale_linters#php#phpstan#GetCommand'),
104 \ 'callback': 'ale_linters#php#phpstan#Handle',
105 \ 'cwd': function('ale_linters#php#phpstan#GetCwd'),