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: chocoelho <carlospecter@gmail.com>
2 " Description: prospector linter python files
4 call ale#Set('python_prospector_auto_pipenv', 0)
5 call ale#Set('python_prospector_auto_poetry', 0)
6 call ale#Set('python_prospector_auto_uv', 0)
8 let g:ale_python_prospector_executable =
9 \ get(g:, 'ale_python_prospector_executable', 'prospector')
11 let g:ale_python_prospector_options =
12 \ get(g:, 'ale_python_prospector_options', '')
14 let g:ale_python_prospector_use_global = get(g:, 'ale_python_prospector_use_global', get(g:, 'ale_use_global_executables', 0))
16 function! ale_linters#python#prospector#GetExecutable(buffer) abort
17 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_prospector_auto_pipenv'))
18 \ && ale#python#PipenvPresent(a:buffer)
22 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_prospector_auto_poetry'))
23 \ && ale#python#PoetryPresent(a:buffer)
27 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_prospector_auto_uv'))
28 \ && ale#python#UvPresent(a:buffer)
32 return ale#python#FindExecutable(a:buffer, 'python_prospector', ['prospector'])
35 function! ale_linters#python#prospector#GetCommand(buffer) abort
36 let l:executable = ale_linters#python#prospector#GetExecutable(a:buffer)
38 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
42 return ale#Escape(l:executable)
44 \ . ' ' . ale#Var(a:buffer, 'python_prospector_options')
45 \ . ' --messages-only --absolute-paths --zero-exit --output-format json'
49 function! ale_linters#python#prospector#Handle(buffer, lines) abort
56 let l:prospector_error = json_decode(join(a:lines, ''))
58 for l:error in l:prospector_error.messages
59 if (l:error.code is# 'W291' || l:error.code is# 'W293' || l:error.code is# 'trailing-whitespace')
60 \ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
61 " Skip warnings for trailing whitespace if the option is off.
65 if l:error.code is# 'W391'
66 \&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
67 " Skip warnings for trailing blank lines if the option is off
71 if l:error.source =~# '\v\[%(dodgy|mccabe|pep8|pep257|pyroma)\]$'
72 let l:sub_type = 'style'
77 if l:error.source =~# '\v\[pylint\]$'
78 let l:type = l:error.code =~? '\m^[CRW]' ? 'W' : 'E'
79 elseif l:error.source =~# '\v\[%(frosted|pep8)\]$'
80 let l:type = l:error.code =~? '\m^W' ? 'W' : 'E'
81 elseif l:error.source =~# '\v\[%(dodgy|pyroma|vulture)\]$'
88 \ 'lnum': l:error.location.line,
89 \ 'col': l:error.location.character + 1,
90 \ 'text': l:error.message,
91 \ 'code': printf('(%s) %s', l:error.source, l:error.code),
93 \ 'sub_type': l:sub_type,
100 call add(l:output, l:item)
106 call ale#linter#Define('python', {
107 \ 'name': 'prospector',
108 \ 'executable': function('ale_linters#python#prospector#GetExecutable'),
109 \ 'command': function('ale_linters#python#prospector#GetCommand'),
110 \ 'callback': 'ale_linters#python#prospector#Handle',