]> git.madduck.net Git - etc/vim.git/blob - ale_linters/python/pyflakes.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 / pyflakes.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: pyflakes for python files
3
4 call ale#Set('python_pyflakes_executable', 'pyflakes')
5 call ale#Set('python_pyflakes_use_global', get(g:, 'ale_use_global_executables', 0))
6 call ale#Set('python_pyflakes_auto_pipenv', 0)
7 call ale#Set('python_pyflakes_auto_poetry', 0)
8 call ale#Set('python_pyflakes_auto_uv', 0)
9
10 function! ale_linters#python#pyflakes#GetExecutable(buffer) abort
11     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyflakes_auto_pipenv'))
12     \ && ale#python#PipenvPresent(a:buffer)
13         return 'pipenv'
14     endif
15
16     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyflakes_auto_poetry'))
17     \ && ale#python#PoetryPresent(a:buffer)
18         return 'poetry'
19     endif
20
21     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pyflakes_auto_uv'))
22     \ && ale#python#UvPresent(a:buffer)
23         return 'uv'
24     endif
25
26     return ale#python#FindExecutable(a:buffer, 'python_pyflakes', ['pyflakes'])
27 endfunction
28
29 function! ale_linters#python#pyflakes#GetCommand(buffer) abort
30     let l:executable = ale_linters#python#pyflakes#GetExecutable(a:buffer)
31
32     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
33     \   ? ' run pyflakes'
34     \   : ''
35
36     return ale#Escape(l:executable)
37     \   . l:exec_args
38     \   . ' %t'
39 endfunction
40
41 function! ale_linters#python#pyflakes#Handle(buffer, lines) abort
42     let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.+)$'
43     let l:output = []
44
45     for l:match in ale#util#GetMatches(a:lines, l:pattern)
46         call add(l:output, {
47         \   'lnum': l:match[1] + 0,
48         \   'col': l:match[2] + 0,
49         \   'text': l:match[3],
50         \})
51     endfor
52
53     return l:output
54 endfunction
55
56 call ale#linter#Define('python', {
57 \   'name': 'pyflakes',
58 \   'executable': function('ale_linters#python#pyflakes#GetExecutable'),
59 \   'command': function('ale_linters#python#pyflakes#GetCommand'),
60 \   'callback': 'ale_linters#python#pyflakes#Handle',
61 \   'output_stream': 'both',
62 \})