Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

black fixer: --pyi option was appended without a space #3759

Merged
merged 1 commit into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions autoload/ale/fixers/black.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ endfunction

function! ale#fixers#black#Fix(buffer) abort
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv$'
\ ? ' run black'
\ : ''
let l:cmd = [ale#Escape(l:executable)]

if l:executable =~? 'pipenv$'
call extend(l:cmd, ['run', 'black'])
endif

let l:options = ale#Var(a:buffer, 'python_black_options')

if !empty(l:options)
call add(l:cmd, l:options)
endif

if expand('#' . a:buffer . ':e') is? 'pyi'
let l:options .= '--pyi'
call add(l:cmd, '--pyi')
endif

let l:result = {
\ 'command': ale#Escape(l:executable) . l:exec_args
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -',
\}
call add(l:cmd, '-')

let l:result = {'command': join(l:cmd, ' ')}

if ale#Var(a:buffer, 'python_black_change_directory')
let l:result.cwd = '%s:h'
Expand Down
10 changes: 10 additions & 0 deletions test/fixers/test_black_fixer_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ Execute(The black callback should include --pyi for .pyi files):
\ {'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/black')) . ' --pyi -' },
\ ale#fixers#black#Fix(bufnr(''))

Execute(The black callback should not concatenate options):
let g:ale_python_black_options = '--some-option'
let g:ale_python_black_change_directory = 0

silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.pyi')

AssertEqual
\ {'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/black')) . ' --some-option --pyi -' },
\ ale#fixers#black#Fix(bufnr(''))

Execute(Pipenv is detected when python_black_auto_pipenv is set):
let g:ale_python_black_auto_pipenv = 1
let g:ale_python_black_change_directory = 0
Expand Down