]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/python/pycodestyle.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 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
[etc/vim.git] / .vim / bundle / ale / ale_linters / python / pycodestyle.vim
1 " Author: Michael Thiesen <micthiesen@gmail.com>
2 " Description: pycodestyle linting for python files
3
4 call ale#Set('python_pycodestyle_executable', 'pycodestyle')
5 call ale#Set('python_pycodestyle_options', '')
6 call ale#Set('python_pycodestyle_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_pycodestyle_auto_pipenv', 0)
8 call ale#Set('python_pycodestyle_auto_poetry', 0)
9 call ale#Set('python_pycodestyle_auto_uv', 0)
10
11 function! ale_linters#python#pycodestyle#GetExecutable(buffer) abort
12     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pycodestyle_auto_pipenv'))
13     \ && ale#python#PipenvPresent(a:buffer)
14         return 'pipenv'
15     endif
16
17     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pycodestyle_auto_poetry'))
18     \ && ale#python#PoetryPresent(a:buffer)
19         return 'poetry'
20     endif
21
22     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pycodestyle_auto_uv'))
23     \ && ale#python#UvPresent(a:buffer)
24         return 'uv'
25     endif
26
27     return ale#python#FindExecutable(a:buffer, 'python_pycodestyle', ['pycodestyle'])
28 endfunction
29
30 function! ale_linters#python#pycodestyle#GetCommand(buffer) abort
31     let l:executable = ale_linters#python#pycodestyle#GetExecutable(a:buffer)
32
33     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
34     \   ? ' run pycodestyle'
35     \   : ''
36
37     return ale#Escape(l:executable) . l:exec_args
38     \   . ' '
39     \   . ale#Var(a:buffer, 'python_pycodestyle_options')
40     \   . ' -'
41 endfunction
42
43 function! ale_linters#python#pycodestyle#Handle(buffer, lines) abort
44     let l:pattern = '\v^(\S*):(\d*):(\d*): ([EW]\d+) (.*)$'
45     let l:output = []
46
47     " lines are formatted as follows:
48     " file.py:21:26: W291 trailing whitespace
49     for l:match in ale#util#GetMatches(a:lines, l:pattern)
50         if(l:match[4] is# 'W291' || l:match[4] is# 'W293')
51         \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
52             " Skip warnings for trailing whitespace if the option is off.
53             continue
54         endif
55
56         if l:match[4] is# 'W391'
57         \&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
58             " Skip warnings for trailing blank lines if the option is off
59             continue
60         endif
61
62         let l:item = {
63         \   'lnum': l:match[2] + 0,
64         \   'col': l:match[3] + 0,
65         \   'type': l:match[4][0],
66         \   'sub_type': 'style',
67         \   'text': l:match[5],
68         \   'code': l:match[4],
69         \}
70
71         " E999 and E112 are syntax errors.
72         if l:match[4] is# 'E999' || l:match[4] is# 'E112'
73             unlet l:item.sub_type
74         endif
75
76         call add(l:output, l:item)
77     endfor
78
79     return l:output
80 endfunction
81
82 call ale#linter#Define('python', {
83 \   'name': 'pycodestyle',
84 \   'executable': function('ale_linters#python#pycodestyle#GetExecutable'),
85 \   'command': function('ale_linters#python#pycodestyle#GetCommand'),
86 \   'callback': 'ale_linters#python#pycodestyle#Handle',
87 \})