diff options
Diffstat (limited to 'ale_linters/python')
-rw-r--r-- | ale_linters/python/bandit.vim | 58 | ||||
-rw-r--r-- | ale_linters/python/flake8.vim | 2 | ||||
-rw-r--r-- | ale_linters/python/pyls.vim | 2 |
3 files changed, 61 insertions, 1 deletions
diff --git a/ale_linters/python/bandit.vim b/ale_linters/python/bandit.vim new file mode 100644 index 00000000..1b5a84a4 --- /dev/null +++ b/ale_linters/python/bandit.vim @@ -0,0 +1,58 @@ +" Author: Martino Pilia <martino.pilia@gmail.com> +" Description: bandit linting for python files + +call ale#Set('python_bandit_executable', 'bandit') +call ale#Set('python_bandit_options', '') +call ale#Set('python_bandit_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('python_bandit_auto_pipenv', 0) + +function! ale_linters#python#bandit#GetExecutable(buffer) abort + if (ale#Var(a:buffer, 'python_auto_pipenv') || + \ ale#Var(a:buffer, 'python_bandit_auto_pipenv')) + \ && ale#python#PipenvPresent(a:buffer) + return 'pipenv' + endif + + return ale#python#FindExecutable(a:buffer, 'python_bandit', ['bandit']) +endfunction + +function! ale_linters#python#bandit#GetCommand(buffer) abort + let l:executable = ale_linters#python#bandit#GetExecutable(a:buffer) + let l:flags = ' --format custom' + \ . ' --msg-template "{line}:{test_id}:{severity}:{msg}" ' + + let l:exec_args = l:executable =~? 'pipenv$' + \ ? ' run bandit' + \ : '' + + return ale#Escape(l:executable) . l:exec_args + \ . l:flags + \ . ale#Pad(ale#Var(a:buffer, 'python_bandit_options')) + \ . ' -' +endfunction + +function! ale_linters#python#bandit#Handle(buffer, lines) abort + " Custom format defined in GetCommand via --msg-template + let l:pattern = '\v^([0-9]+):(B[0-9]+):([A-Z]+):(.*)$' + let l:severity = {'LOW': 'I', 'MEDIUM': 'W', 'HIGH': 'E'} + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': str2nr(l:match[1]), + \ 'code': l:match[2], + \ 'type': l:severity[l:match[3]], + \ 'text': l:match[4], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('python', { +\ 'name': 'bandit', +\ 'executable_callback': 'ale_linters#python#bandit#GetExecutable', +\ 'command_callback': 'ale_linters#python#bandit#GetCommand', +\ 'callback': 'ale_linters#python#bandit#Handle', +\}) diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim index 14b67d77..b5b5f3cc 100644 --- a/ale_linters/python/flake8.vim +++ b/ale_linters/python/flake8.vim @@ -89,7 +89,7 @@ function! ale_linters#python#flake8#Handle(buffer, lines) abort " Matches patterns line the following: " " stdin:6:6: E111 indentation is not a multiple of four - let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: ([[:alnum:]]+) (.*)$' + let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: ([[:alnum:]]+):? (.*)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) diff --git a/ale_linters/python/pyls.vim b/ale_linters/python/pyls.vim index 83fe8066..2c2ed94c 100644 --- a/ale_linters/python/pyls.vim +++ b/ale_linters/python/pyls.vim @@ -4,6 +4,7 @@ call ale#Set('python_pyls_executable', 'pyls') call ale#Set('python_pyls_use_global', get(g:, 'ale_use_global_executables', 0)) call ale#Set('python_pyls_auto_pipenv', 0) +call ale#Set('python_pyls_config', {}) function! ale_linters#python#pyls#GetExecutable(buffer) abort if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyls_auto_pipenv')) @@ -31,4 +32,5 @@ call ale#linter#Define('python', { \ 'command_callback': 'ale_linters#python#pyls#GetCommand', \ 'project_root_callback': 'ale#python#FindProjectRoot', \ 'completion_filter': 'ale#completion#python#CompletionItemFilter', +\ 'lsp_config_callback': ale#VarFunc('python_pyls_config'), \}) |