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: Martino Pilia <martino.pilia@gmail.com>
2 " Description: bandit linting for python files
4 call ale#Set('python_bandit_executable', 'bandit')
5 call ale#Set('python_bandit_options', '')
6 call ale#Set('python_bandit_use_config', 1)
7 call ale#Set('python_bandit_use_global', get(g:, 'ale_use_global_executables', 0))
8 call ale#Set('python_bandit_auto_pipenv', 0)
9 call ale#Set('python_bandit_auto_poetry', 0)
10 call ale#Set('python_bandit_auto_uv', 0)
12 function! ale_linters#python#bandit#GetExecutable(buffer) abort
14 \ ale#Var(a:buffer, 'python_auto_pipenv')
15 \ || ale#Var(a:buffer, 'python_bandit_auto_pipenv')
16 \) && ale#python#PipenvPresent(a:buffer)
21 \ ale#Var(a:buffer, 'python_auto_poetry')
22 \ || ale#Var(a:buffer, 'python_bandit_auto_poetry')
23 \) && ale#python#PoetryPresent(a:buffer)
27 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_bandit_auto_uv'))
28 \ && ale#python#UvPresent(a:buffer)
32 return ale#python#FindExecutable(a:buffer, 'python_bandit', ['bandit'])
35 function! ale_linters#python#bandit#GetCommand(buffer) abort
36 let l:executable = ale_linters#python#bandit#GetExecutable(a:buffer)
37 let l:flags = ' --format custom'
38 \ . ' --msg-template "{line}:{test_id}:{severity}:{msg}" '
40 if ale#Var(a:buffer, 'python_bandit_use_config')
41 let l:config_path = ale#path#FindNearestFile(a:buffer, '.bandit')
43 if !empty(l:config_path)
44 let l:flags = ' --ini ' . ale#Escape(l:config_path) . l:flags
48 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
52 return ale#Escape(l:executable) . l:exec_args
54 \ . ale#Pad(ale#Var(a:buffer, 'python_bandit_options'))
58 function! ale_linters#python#bandit#Handle(buffer, lines) abort
59 " Custom format defined in GetCommand via --msg-template
60 let l:pattern = '\v^([0-9]+):(B[0-9]+):([A-Z]+):(.*)$'
61 let l:severity = {'LOW': 'I', 'MEDIUM': 'W', 'HIGH': 'E'}
64 for l:match in ale#util#GetMatches(a:lines, l:pattern)
67 \ 'lnum': str2nr(l:match[1]),
69 \ 'type': l:severity[l:match[3]],
77 call ale#linter#Define('python', {
79 \ 'executable': function('ale_linters#python#bandit#GetExecutable'),
80 \ 'command': function('ale_linters#python#bandit#GetCommand'),
81 \ 'callback': 'ale_linters#python#bandit#Handle',