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: Yining <zhang.yining@gmail.com>
2 " Description: pycln as linter for python files
4 call ale#Set('python_pycln_executable', 'pycln')
5 call ale#Set('python_pycln_options', '')
6 call ale#Set('python_pycln_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_pycln_change_directory', 1)
8 call ale#Set('python_pycln_auto_pipenv', 0)
9 call ale#Set('python_pycln_auto_poetry', 0)
10 call ale#Set('python_pycln_auto_uv', 0)
11 call ale#Set('python_pycln_config_file', '')
13 function! ale_linters#python#pycln#GetExecutable(buffer) abort
14 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pycln_auto_pipenv'))
15 \ && ale#python#PipenvPresent(a:buffer)
19 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pycln_auto_poetry'))
20 \ && ale#python#PoetryPresent(a:buffer)
24 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pycln_auto_uv'))
25 \ && ale#python#UvPresent(a:buffer)
29 return ale#python#FindExecutable(a:buffer, 'python_pycln', ['pycln'])
32 function! ale_linters#python#pycln#GetCwd(buffer) abort
33 if ale#Var(a:buffer, 'python_pycln_change_directory')
34 " Run from project root if found, else from buffer dir.
35 let l:project_root = ale#python#FindProjectRoot(a:buffer)
37 return !empty(l:project_root) ? l:project_root : '%s:h'
43 function! ale_linters#python#pycln#GetCommand(buffer, version) abort
44 let l:executable = ale_linters#python#pycln#GetExecutable(a:buffer)
45 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
49 let l:options = ale#Var(a:buffer, 'python_pycln_options')
50 let l:config_file = ale#Var(a:buffer, 'python_pycln_config_file')
51 let l:config_file = l:options !~# '\v(^| )--config ' && !empty(l:config_file)
52 \ ? ale#Escape(ale#path#Simplify(l:config_file))
55 " NOTE: pycln version `1.3.0` supports liniting input from stdin
56 return ale#Escape(l:executable) . l:exec_args
57 \ . ale#Pad(ale#Var(a:buffer, 'python_pycln_options'))
58 \ . (empty(l:config_file) ? '' : ' --config ' . l:config_file)
60 \ . (ale#semver#GTE(a:version, [1, 3, 0]) ? ' -' : ' %s')
63 function! ale_linters#python#pycln#Handle(buffer, lines) abort
64 " Example: tmp/test.py:3:0 'import os' would be removed!
65 let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+):? (.+)$'
68 for l:match in ale#util#GetMatches(a:lines, l:pattern)
70 \ 'lnum': l:match[1] + 0,
71 \ 'col': l:match[2] + 0,
79 call ale#linter#Define('python', {
81 \ 'executable': function('ale_linters#python#pycln#GetExecutable'),
82 \ 'cwd': function('ale_linters#python#pycln#GetCwd'),
83 \ 'command': {buffer -> ale#semver#RunWithVersionCheck(
85 \ ale_linters#python#pycln#GetExecutable(buffer),
87 \ function('ale_linters#python#pycln#GetCommand'),
89 \ 'callback': 'ale_linters#python#pycln#Handle',
90 \ 'output_stream': 'both',