]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/python/prospector.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / python / prospector.vim
1 " Author: chocoelho <carlospecter@gmail.com>
2 " Description: prospector linter python files
3
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)
7
8 let g:ale_python_prospector_executable =
9 \   get(g:, 'ale_python_prospector_executable', 'prospector')
10
11 let g:ale_python_prospector_options =
12 \   get(g:, 'ale_python_prospector_options', '')
13
14 let g:ale_python_prospector_use_global = get(g:, 'ale_python_prospector_use_global', get(g:, 'ale_use_global_executables', 0))
15
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)
19         return 'pipenv'
20     endif
21
22     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_prospector_auto_poetry'))
23     \ && ale#python#PoetryPresent(a:buffer)
24         return 'poetry'
25     endif
26
27     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_prospector_auto_uv'))
28     \ && ale#python#UvPresent(a:buffer)
29         return 'uv'
30     endif
31
32     return ale#python#FindExecutable(a:buffer, 'python_prospector', ['prospector'])
33 endfunction
34
35 function! ale_linters#python#prospector#GetCommand(buffer) abort
36     let l:executable = ale_linters#python#prospector#GetExecutable(a:buffer)
37
38     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
39     \   ? ' run prospector'
40     \   : ''
41
42     return ale#Escape(l:executable)
43     \   . l:exec_args
44     \   . ' ' . ale#Var(a:buffer, 'python_prospector_options')
45     \   . ' --messages-only --absolute-paths --zero-exit --output-format json'
46     \   . ' %s'
47 endfunction
48
49 function! ale_linters#python#prospector#Handle(buffer, lines) abort
50     let l:output = []
51
52     if empty(a:lines)
53         return []
54     endif
55
56     let l:prospector_error = json_decode(join(a:lines, ''))
57
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.
62             continue
63         endif
64
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
68             continue
69         endif
70
71         if l:error.source =~# '\v\[%(dodgy|mccabe|pep8|pep257|pyroma)\]$'
72             let l:sub_type = 'style'
73         else
74             let l:sub_type = ''
75         endif
76
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)\]$'
82             let l:type = 'W'
83         else
84             let l:type = 'E'
85         endif
86
87         let l:item = {
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),
92         \   'type': l:type,
93         \   'sub_type': l:sub_type,
94         \}
95
96         if l:sub_type is# ''
97             unlet l:item.sub_type
98         endif
99
100         call add(l:output, l:item)
101     endfor
102
103     return l:output
104 endfunction
105
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',
111 \   'lint_file': 1,
112 \})