mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/ale/autoload/ale/fixers/black.vim

47 lines
1.3 KiB
VimL
Raw Normal View History

2018-06-14 06:31:12 -04:00
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing Python files with black.
"
call ale#Set('python_black_executable', 'black')
call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('python_black_options', '')
2019-01-08 05:11:54 -05:00
call ale#Set('python_black_auto_pipenv', 0)
2019-03-08 06:04:56 -05:00
call ale#Set('python_black_change_directory', 1)
2019-01-08 05:11:54 -05:00
function! ale#fixers#black#GetExecutable(buffer) abort
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv'))
\ && ale#python#PipenvPresent(a:buffer)
return 'pipenv'
endif
return ale#python#FindExecutable(a:buffer, 'python_black', ['black'])
endfunction
2018-06-14 06:31:12 -04:00
function! ale#fixers#black#Fix(buffer) abort
2019-01-08 05:11:54 -05:00
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
2021-07-04 16:47:44 -04:00
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv$'
call extend(l:cmd, ['run', 'black'])
endif
2018-06-14 06:31:12 -04:00
let l:options = ale#Var(a:buffer, 'python_black_options')
2021-07-04 16:47:44 -04:00
if !empty(l:options)
call add(l:cmd, l:options)
endif
2019-08-22 11:36:17 -04:00
if expand('#' . a:buffer . ':e') is? 'pyi'
2021-07-04 16:47:44 -04:00
call add(l:cmd, '--pyi')
2019-08-22 11:36:17 -04:00
endif
2021-07-04 16:47:44 -04:00
call add(l:cmd, '-')
let l:result = {'command': join(l:cmd, ' ')}
2021-05-05 04:25:00 -04:00
if ale#Var(a:buffer, 'python_black_change_directory')
let l:result.cwd = '%s:h'
endif
return l:result
2018-06-14 06:31:12 -04:00
endfunction