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: keith <k@keith.so>
2 " Description: pylint for python files
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)
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)
19 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pylint_auto_poetry'))
20 \ && ale#python#PoetryPresent(a:buffer)
24 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pylint_auto_uv'))
25 \ && ale#python#UvPresent(a:buffer)
29 return ale#python#FindExecutable(a:buffer, 'python_pylint', ['pylint'])
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)
39 return !empty(l:project_root) ? l:project_root : '%s:h'
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\)$'
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' : '')
58 function! ale_linters#python#pylint#Handle(buffer, lines) abort
59 let l:output = ale#python#HandleTraceback(a:lines, 10)
65 " Matches patterns like the following:
67 " test.py:4:4: W0101 (unreachable) Unreachable code
68 let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+): ([[:alnum:]]+) \(([^(]*)\) (.*)$'
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]
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.
81 " Skip 'Locally disabling' message
85 if ale#Var(a:buffer, 'python_pylint_use_msg_id')
86 let l:code_out = l:code
88 let l:code_out = l:match[4]
92 \ 'lnum': l:match[1] + 0,
93 \ 'col': l:match[2] + 1,
100 let l:item.type = 'E'
103 call add(l:output, l:item)
109 call ale#linter#Define('python', {
111 \ 'executable': function('ale_linters#python#pylint#GetExecutable'),
112 \ 'lint_file': {buffer -> ale#semver#RunWithVersionCheck(
114 \ ale#Var(buffer, 'python_pylint_executable'),
116 \ {buffer, version -> !ale#semver#GTE(version, [2, 4, 0])},
118 \ 'cwd': function('ale_linters#python#pylint#GetCwd'),
119 \ 'command': {buffer -> ale#semver#RunWithVersionCheck(
121 \ ale#Var(buffer, 'python_pylint_executable'),
123 \ function('ale_linters#python#pylint#GetCommand'),
125 \ 'callback': 'ale_linters#python#pylint#Handle',