Skip to content

Commit

Permalink
Fix flake8 cd logic for invalid options
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Aug 31, 2020
1 parent cdaeca4 commit ac2100d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
26 changes: 11 additions & 15 deletions ale_linters/python/flake8.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,23 @@ endfunction

function! ale_linters#python#flake8#GetCdString(buffer) abort
let l:change_directory = ale#Var(a:buffer, 'python_flake8_change_directory')
let l:cd_string = ''

" map legacy options to new ones
if l:change_directory is# 1
let l:change_directory = 'file'
elseif l:change_directory is# 0
let l:change_directory = 'off'
endif
if l:change_directory is# 'project'
let l:project_root = ale#python#FindProjectRootIni(a:buffer)

if l:change_directory is# 'file'
return ale#path#BufferCdString(a:buffer)
elseif l:change_directory is# 'off'
return ''
if !empty(l:project_root)
let l:cd_string = ale#path#CdString(l:project_root)
endif
endif

let l:project_root = ale#python#FindProjectRootIni(a:buffer)

if !empty(l:project_root)
return ale#path#CdString(l:project_root)
if (l:change_directory is# 'project' && empty(l:cd_string))
\|| l:change_directory is# 1
\|| l:change_directory is# 'file'
let l:cd_string = ale#path#BufferCdString(a:buffer)
endif

return ale#path#BufferCdString(a:buffer)
return l:cd_string
endfunction

function! ale_linters#python#flake8#GetCommand(buffer, version) abort
Expand Down
20 changes: 20 additions & 0 deletions test/command_callback/test_flake8_command_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ Execute(The option for disabling changing directories should work):
\ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\]

let g:ale_python_flake8_change_directory = 0

AssertLinter 'flake8', [
\ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\]

" Invalid options should be considered the same as turning the setting off.
let g:ale_python_flake8_change_directory = 'xxx'

AssertLinter 'flake8', [
\ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\]

Execute(The option for changing directory to project root should work):
silent execute 'file ' . fnameescape(g:dir . '/python_paths/namespace_package_tox/namespace/foo/bar.py')

Expand All @@ -60,6 +73,13 @@ Execute(The option for changing directory to file dir should work):
\ . ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\]

let g:ale_python_flake8_change_directory = 1

AssertLinter 'flake8', [
\ ale#path#BufferCdString(bufnr(''))
\ . ale#Escape('flake8') . ' --format=default --stdin-display-name %s -',
\]

Execute(The flake8 command callback should let you set options):
let g:ale_python_flake8_options = '--some-option'

Expand Down

0 comments on commit ac2100d

Please sign in to comment.