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: refurb as linter for python files
4 call ale#Set('python_refurb_executable', 'refurb')
5 call ale#Set('python_refurb_options', '')
6 call ale#Set('python_refurb_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('python_refurb_change_directory', 1)
8 call ale#Set('python_refurb_auto_pipenv', 0)
9 call ale#Set('python_refurb_auto_poetry', 0)
10 call ale#Set('python_refurb_auto_uv', 0)
12 function! ale_linters#python#refurb#GetExecutable(buffer) abort
13 if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_refurb_auto_pipenv'))
14 \ && ale#python#PipenvPresent(a:buffer)
18 if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_refurb_auto_poetry'))
19 \ && ale#python#PoetryPresent(a:buffer)
23 if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_refurb_auto_uv'))
24 \ && ale#python#UvPresent(a:buffer)
28 return ale#python#FindExecutable(a:buffer, 'python_refurb', ['refurb'])
31 function! ale_linters#python#refurb#GetCwd(buffer) abort
32 if ale#Var(a:buffer, 'python_refurb_change_directory')
33 " Run from project root if found, else from buffer dir.
34 let l:project_root = ale#python#FindProjectRoot(a:buffer)
36 return !empty(l:project_root) ? l:project_root : '%s:h'
42 function! ale_linters#python#refurb#GetCommand(buffer) abort
43 let l:executable = ale_linters#python#refurb#GetExecutable(a:buffer)
44 let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
48 return ale#Escape(l:executable) . l:exec_args
49 \ . ale#Pad(ale#Var(a:buffer, 'python_refurb_options'))
53 function! ale_linters#python#refurb#Handle(buffer, lines) abort
54 "Example: path/to/file.py:3:17 [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)`
55 let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+)?:?\s*\[FURB(\d+)\]:\s*(.+)$'
58 for l:match in ale#util#GetMatches(a:lines, l:pattern)
60 \ 'lnum': l:match[1] + 0,
61 \ 'col': l:match[2] + 0,
62 \ 'code': l:match[3] + 0,
71 call ale#linter#Define('python', {
73 \ 'executable': function('ale_linters#python#refurb#GetExecutable'),
74 \ 'cwd': function('ale_linters#python#refurb#GetCwd'),
75 \ 'command': function('ale_linters#python#refurb#GetCommand'),
76 \ 'callback': 'ale_linters#python#refurb#Handle',
77 \ 'output_stream': 'both',