]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/python/pylint.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 / pylint.vim
1 " Author: keith <k@keith.so>
2 " Description: pylint for python files
3
4 call ale#Set('python_pylint_executable', 'pylint')
5 call ale#Set('python_pylint_options', '')
6 call ale#Set('python_pylint_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_pylint_change_directory', 1)
8 call ale#Set('python_pylint_auto_pipenv', 0)
9 call ale#Set('python_pylint_auto_poetry', 0)
10 call ale#Set('python_pylint_auto_uv', 0)
11 call ale#Set('python_pylint_use_msg_id', 0)
12
13 function! ale_linters#python#pylint#GetExecutable(buffer) abort
14     if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pylint_auto_pipenv'))
15     \ && ale#python#PipenvPresent(a:buffer)
16         return 'pipenv'
17     endif
18
19     if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pylint_auto_poetry'))
20     \ && ale#python#PoetryPresent(a:buffer)
21         return 'poetry'
22     endif
23
24     if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pylint_auto_uv'))
25     \ && ale#python#UvPresent(a:buffer)
26         return 'uv'
27     endif
28
29     return ale#python#FindExecutable(a:buffer, 'python_pylint', ['pylint'])
30 endfunction
31
32 function! ale_linters#python#pylint#GetCwd(buffer) abort
33     if ale#Var(a:buffer, 'python_pylint_change_directory')
34         " pylint only checks for pylintrc in the packages above its current
35         " directory before falling back to user and global pylintrc.
36         " Run from project root, if found, otherwise buffer dir.
37         let l:project_root = ale#python#FindProjectRoot(a:buffer)
38
39         return !empty(l:project_root) ? l:project_root : '%s:h'
40     endif
41
42     return ''
43 endfunction
44
45 function! ale_linters#python#pylint#GetCommand(buffer, version) abort
46     let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer)
47     let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
48     \   ? ' run pylint'
49     \   : ''
50
51     return ale#Escape(l:executable) . l:exec_args
52     \   . ale#Pad(ale#Var(a:buffer, 'python_pylint_options'))
53     \   . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n'
54     \   .  (ale#semver#GTE(a:version, [2, 4, 0]) ? ' --from-stdin' : '')
55     \   . ' %s'
56 endfunction
57
58 function! ale_linters#python#pylint#Handle(buffer, lines) abort
59     let l:output = ale#python#HandleTraceback(a:lines, 10)
60
61     if !empty(l:output)
62         return l:output
63     endif
64
65     " Matches patterns like the following:
66     "
67     " test.py:4:4: W0101 (unreachable) Unreachable code
68     let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+): ([[:alnum:]]+) \(([^(]*)\) (.*)$'
69
70     for l:match in ale#util#GetMatches(a:lines, l:pattern)
71         "let l:failed = append(0, l:match)
72         let l:code = l:match[3]
73
74         if (l:code is# 'C0303')
75         \ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
76             " Skip warnings for trailing whitespace if the option is off.
77             continue
78         endif
79
80         if l:code is# 'I0011'
81             " Skip 'Locally disabling' message
82             continue
83         endif
84
85         if ale#Var(a:buffer, 'python_pylint_use_msg_id')
86             let l:code_out = l:code
87         else
88             let l:code_out = l:match[4]
89         endif
90
91         let l:item = {
92         \   'lnum': l:match[1] + 0,
93         \   'col': l:match[2] + 1,
94         \   'text': l:match[5],
95         \   'code': l:code_out,
96         \   'type': 'W',
97         \}
98
99         if l:code[:0] is# 'E'
100             let l:item.type = 'E'
101         endif
102
103         call add(l:output, l:item)
104     endfor
105
106     return l:output
107 endfunction
108
109 call ale#linter#Define('python', {
110 \   'name': 'pylint',
111 \   'executable': function('ale_linters#python#pylint#GetExecutable'),
112 \   'lint_file': {buffer -> ale#semver#RunWithVersionCheck(
113 \       buffer,
114 \       ale#Var(buffer, 'python_pylint_executable'),
115 \       '%e --version',
116 \       {buffer, version -> !ale#semver#GTE(version, [2, 4, 0])},
117 \   )},
118 \   'cwd': function('ale_linters#python#pylint#GetCwd'),
119 \   'command': {buffer -> ale#semver#RunWithVersionCheck(
120 \       buffer,
121 \       ale#Var(buffer, 'python_pylint_executable'),
122 \       '%e --version',
123 \       function('ale_linters#python#pylint#GetCommand'),
124 \   )},
125 \   'callback': 'ale_linters#python#pylint#Handle',
126 \})