Open massimiliano-della-rovere opened 1 year ago
Looking at bandit's linter implementation in ALE I can see two things:
pyproject.toml
it tries to find a .bandit
configuration file and if found it add this argument to the command: --ini /path/to/.bandit
. Maybe something changed in recent versions of bandit and now requires pyproject.toml instead of .bandit??The linter implementation would need to either replace the code to find .bandit with code to find pyproject.toml and set proper argument to the command when invoking bandit.
Code in question is below:
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}" '
if ale#Var(a:buffer, 'python_bandit_use_config')
let l:config_path = ale#path#FindNearestFile(a:buffer, '.bandit')
if !empty(l:config_path)
let l:flags = ' --ini ' . ale#Escape(l:config_path) . l:flags
endif
endif
let l:exec_args = l:executable =~? 'pipenv\|poetry$'
\ ? ' run bandit'
\ : ''
return ale#Escape(l:executable) . l:exec_args
\ . l:flags
\ . ale#Pad(ale#Var(a:buffer, 'python_bandit_options'))
\ . ' -'
endfunction
Information
VIM version
VIM - Vi IMproved 9.0 (2022 Jun 28, compilato May 10 2022 08:40:37) Patch included: 1-749
Operating System: Ubuntu 22.04.1 LTS
What went wrong
The way bandit is called is incompatible with bandit's configuration syntax and assumptions. Note this is generally true for every linting program allowing a configuration involving a directory name.
Reproducing the bug
<venv>/bin/bandit --format custom --msg-template "{line}:{test_id}:{severity}:{msg}" - < /tmp/random_directory_id/test_commands.py
instead of<venv>/bin/bandit --format custom --msg-template "{line}:{test_id}:{severity}:{msg}" -c <project_root>/pyproject.toml <project_root>/tests/test_commands.py
-c <project_root>/pyproject.toml
option that allow to customize the bandit behaviour.:ALEInfo