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: Michael Thiesen <micthiesen@gmail.com>
2 " Description: pycodestyle linting for python files
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)
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)
17 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pycodestyle_auto_poetry'))
18 \ && ale#python#PoetryPresent(a:buffer)
22 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pycodestyle_auto_uv'))
23 \ && ale#python#UvPresent(a:buffer)
27 return ale#python#FindExecutable(a:buffer, 'python_pycodestyle', ['pycodestyle'])
30 function! ale_linters#python#pycodestyle#GetCommand(buffer) abort
31 let l:executable = ale_linters#python#pycodestyle#GetExecutable(a:buffer)
33 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
34 \ ? ' run pycodestyle'
37 return ale#Escape(l:executable) . l:exec_args
39 \ . ale#Var(a:buffer, 'python_pycodestyle_options')
43 function! ale_linters#python#pycodestyle#Handle(buffer, lines) abort
44 let l:pattern = '\v^(\S*):(\d*):(\d*): ([EW]\d+) (.*)$'
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.
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
63 \ 'lnum': l:match[2] + 0,
64 \ 'col': l:match[3] + 0,
65 \ 'type': l:match[4][0],
66 \ 'sub_type': 'style',
71 " E999 and E112 are syntax errors.
72 if l:match[4] is# 'E999' || l:match[4] is# 'E112'
76 call add(l:output, l:item)
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',