]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/python/pydocstyle.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 / pydocstyle.vim
1 " Author: Pablo Acosta <pmasdev@gmail.com>
2 " Description: pydocstyle for python files
3
4 call ale#Set('python_pydocstyle_executable', 'pydocstyle')
5 call ale#Set('python_pydocstyle_options', '')
6 call ale#Set('python_pydocstyle_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_pydocstyle_auto_pipenv', 0)
8 call ale#Set('python_pydocstyle_auto_poetry', 0)
9 call ale#Set('python_pydocstyle_auto_uv', 0)
10
11 function! ale_linters#python#pydocstyle#GetExecutable(buffer) abort
12     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pydocstyle_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_pydocstyle_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_pydocstyle_auto_uv'))
23     \ && ale#python#UvPresent(a:buffer)
24         return 'uv'
25     endif
26
27     return ale#python#FindExecutable(a:buffer, 'python_pydocstyle', ['pydocstyle'])
28 endfunction
29
30 function! ale_linters#python#pydocstyle#GetCommand(buffer) abort
31     let l:executable = ale_linters#python#pydocstyle#GetExecutable(a:buffer)
32     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
33     \   ? ' run pydocstyle'
34     \   : ''
35
36     return ale#Escape(l:executable) . l:exec_args
37     \   . ale#Pad(ale#Var(a:buffer, 'python_pydocstyle_options'))
38     \   . ' %s'
39 endfunction
40
41 function! ale_linters#python#pydocstyle#Handle(buffer, lines) abort
42     " Matches patterns like the following:
43     " mydir/myfile.py:33 in public function `myfunction`:
44     "         DXXX: Error description
45     let l:line1_pattern = '\v^.*:\s*(\d+)\s+.*$'
46     let l:line2_pattern = '\v^.*([a-zA-Z]\d+):\s*(.*)$'
47     let l:output = []
48
49     let l:num_lines = len(a:lines)
50     let l:index = 0
51
52     while l:index < l:num_lines
53         let l:lnum = matchlist(a:lines[l:index], l:line1_pattern)
54
55         if !empty(l:lnum) && (l:index + 1 < l:num_lines)
56             let l:desc = matchlist(a:lines[l:index + 1], l:line2_pattern)
57
58             if !empty(l:desc)
59                 call add(l:output, {
60                 \ 'lnum': l:lnum[1] + 0,
61                 \ 'col': 1,
62                 \ 'type': 'W',
63                 \ 'text': l:desc[2],
64                 \ 'code': l:desc[1],
65                 \})
66             endif
67
68             let l:index = l:index + 2
69         else
70             let l:index = l:index + 1
71         endif
72     endwhile
73
74     return l:output
75 endfunction
76
77 call ale#linter#Define('python', {
78 \   'name': 'pydocstyle',
79 \   'executable': function('ale_linters#python#pydocstyle#GetExecutable'),
80 \   'cwd': '%s:h',
81 \   'command': function('ale_linters#python#pydocstyle#GetCommand'),
82 \   'callback': 'ale_linters#python#pydocstyle#Handle',
83 \})