]> git.madduck.net Git - etc/vim.git/blob - ale_linters/python/vulture.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / python / vulture.vim
1 " Author: Yauheni Kirylau <actionless.loveless@gmail.com>
2 " Description: vulture linting for python files
3
4 call ale#Set('python_vulture_executable', 'vulture')
5 call ale#Set('python_vulture_options', '')
6 call ale#Set('python_vulture_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_vulture_change_directory', 1)
8 call ale#Set('python_vulture_auto_pipenv', 0)
9 call ale#Set('python_vulture_auto_poetry', 0)
10 call ale#Set('python_vulture_auto_uv', 0)
11
12 " The directory to change to before running vulture
13 function! s:GetDir(buffer) abort
14     let l:project_root = ale#python#FindProjectRoot(a:buffer)
15
16     return !empty(l:project_root)
17     \   ? l:project_root
18     \   : expand('#' . a:buffer . ':p:h')
19 endfunction
20
21 function! ale_linters#python#vulture#GetExecutable(buffer) abort
22     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_vulture_auto_pipenv'))
23     \ && ale#python#PipenvPresent(a:buffer)
24         return 'pipenv'
25     endif
26
27     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_vulture_auto_poetry'))
28     \ && ale#python#PoetryPresent(a:buffer)
29         return 'poetry'
30     endif
31
32     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_vulture_auto_uv'))
33     \ && ale#python#UvPresent(a:buffer)
34         return 'uv'
35     endif
36
37     return ale#python#FindExecutable(a:buffer, 'python_vulture', ['vulture'])
38 endfunction
39
40 function! ale_linters#python#vulture#GetCwd(buffer) abort
41     if !ale#Var(a:buffer, 'python_vulture_change_directory')
42         return ''
43     endif
44
45     return s:GetDir(a:buffer)
46 endfunction
47
48 function! ale_linters#python#vulture#GetCommand(buffer) abort
49     let l:executable = ale_linters#python#vulture#GetExecutable(a:buffer)
50     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
51     \   ? ' run vulture'
52     \   : ''
53     let l:lint_dest = ale#Var(a:buffer, 'python_vulture_change_directory')
54     \   ? ' .'
55     \   : ' %s'
56
57     return ale#Escape(l:executable) . l:exec_args
58     \   . ' '
59     \   . ale#Var(a:buffer, 'python_vulture_options')
60     \   . l:lint_dest
61 endfunction
62
63
64 function! ale_linters#python#vulture#Handle(buffer, lines) abort
65     let l:output = ale#python#HandleTraceback(a:lines, 10)
66
67     if !empty(l:output)
68         return l:output
69     endif
70
71     " Matches patterns line the following:
72     let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+): (.*)$'
73     let l:dir = s:GetDir(a:buffer)
74
75     for l:match in ale#util#GetMatches(a:lines, l:pattern)
76         let l:abspath = ale#path#GetAbsPath(l:dir, l:match[1])
77         let l:item = {
78         \   'filename': l:abspath,
79         \   'lnum': l:match[2] + 0,
80         \   'text': l:match[3],
81         \   'type': 'W',
82         \}
83         call add(l:output, l:item)
84     endfor
85
86     return l:output
87 endfunction
88
89
90 call ale#linter#Define('python', {
91 \   'name': 'vulture',
92 \   'executable': function('ale_linters#python#vulture#GetExecutable'),
93 \   'cwd': function('ale_linters#python#vulture#GetCwd'),
94 \   'command': function('ale_linters#python#vulture#GetCommand'),
95 \   'callback': 'ale_linters#python#vulture#Handle',
96 \   'lint_file': 1,
97 \})