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

Adds --memory-limit support for phpstan #3973

Merged
merged 6 commits into from
Nov 12, 2021
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
9 changes: 8 additions & 1 deletion ale_linters/php/phpstan.vim
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
" Author: medains <https://github.com/medains>, ardis <https://github.com/ardisdreelath>
" Author: medains <https://github.com/medains>, ardis <https://github.com/ardisdreelath>, Arizard <https://github.com/Arizard>
" Description: phpstan for PHP files

" Set to change the ruleset
let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpstan')
let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '')
let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '')
let g:ale_php_phpstan_autoload = get(g:, 'ale_php_phpstan_autoload', '')
let g:ale_php_phpstan_memory_limit = get(g:, 'ale_php_phpstan_memory_limit', '')
call ale#Set('php_phpstan_use_global', get(g:, 'ale_use_global_executables', 0))

function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
Expand All @@ -19,6 +20,11 @@ function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
\ ? ' -a ' . ale#Escape(l:autoload)
\ : ''

let l:memory_limit = ale#Var(a:buffer, 'php_phpstan_memory_limit')
let l:memory_limit_option = !empty(l:memory_limit)
\ ? ' --memory-limit ' . ale#Escape(l:memory_limit)
\ : ''

let l:level = ale#Var(a:buffer, 'php_phpstan_level')
let l:config_file_exists = ale#path#FindNearestFile(a:buffer, 'phpstan.neon')
let l:dist_config_file_exists = ale#path#FindNearestFile(a:buffer, 'phpstan.neon.dist')
Expand All @@ -41,6 +47,7 @@ function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
\ . l:configuration_option
\ . l:autoload_option
\ . l:level_option
\ . l:memory_limit_option
\ . ' %s'
endfunction

Expand Down
9 changes: 9 additions & 0 deletions doc/ale-php.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ g:ale_php_phpstan_autoload *g:ale_php_phpstan_autoload*
This variable sets path to phpstan autoload file.


g:ale_php_phpstan_memory_limit *g:ale_php_phpstan_memory-limit*
*b:ale_php_phpstan_memory-limit*
Type: |String|
Default: `''`

This variable sets the memory limit for phpstan analysis. This is a string
in the same format as `php.ini` accepts, e.g. `128M`, `1G`.


===============================================================================
psalm *ale-php-psalm*

Expand Down
6 changes: 6 additions & 0 deletions test/linter/test_phpstan.vader
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ Execute(Autoload parameter is added to the command):

AssertLinter 'phpstan',
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat json -a ' . ale#Escape('autoload.php') . ' -l ' . ale#Escape('4') . ' %s'

Execute(Memory limit parameter is added to the command):
let g:ale_php_phpstan_memory_limit = '500M'

AssertLinter 'phpstan',
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat json -l ' . ale#Escape('4') . ' --memory-limit ' . ale#Escape('500M') . ' %s'