diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim index 4ed4193..9d314d8 100644 --- a/ale_linters/python/flake8.vim +++ b/ale_linters/python/flake8.vim @@ -1,14 +1,13 @@ " Author: w0rp " Description: flake8 for python files -let g:ale_python_flake8_executable = -\ get(g:, 'ale_python_flake8_executable', 'flake8') - " Support an old setting as a fallback. let s:default_options = get(g:, 'ale_python_flake8_args', '') -let g:ale_python_flake8_options = -\ get(g:, 'ale_python_flake8_options', s:default_options) -let g:ale_python_flake8_use_global = get(g:, 'ale_python_flake8_use_global', get(g:, 'ale_use_global_executables', 0)) + +call ale#Set('python_flake8_executable', 'flake8') +call ale#Set('python_flake8_options', s:default_options) +call ale#Set('python_flake8_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('python_flake8_change_directory', 1) function! s:UsingModule(buffer) abort return ale#Var(a:buffer, 'python_flake8_options') =~# ' *-m flake8' @@ -39,7 +38,9 @@ function! ale_linters#python#flake8#VersionCheck(buffer) abort endfunction function! ale_linters#python#flake8#GetCommand(buffer, version_output) abort - let l:cd_string = ale#path#BufferCdString(a:buffer) + let l:cd_string = ale#Var(a:buffer, 'python_flake8_change_directory') + \ ? ale#path#BufferCdString(a:buffer) + \ : '' let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer) let l:version = ale#semver#GetVersion(l:executable, a:version_output) diff --git a/doc/ale-python.txt b/doc/ale-python.txt index e161426..6733007 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -59,6 +59,17 @@ g:ale_python_black_use_global *g:ale_python_black_use_global* =============================================================================== flake8 *ale-python-flake8* +g:ale_python_flake8_change_directory *g:ale_python_flake8_change_directory* + *b:ale_python_flake8_change_directory* + Type: |Number| + Default: `1` + + If set to `1`, ALE will switch to the directory the Python file being + checked with `flake8` is in before checking it. This helps `flake8` find + configuration files more easily. This option can be turned off if you want + to control the directory Python is executed from yourself. + + g:ale_python_flake8_executable *g:ale_python_flake8_executable* *b:ale_python_flake8_executable* Type: |String| diff --git a/test/command_callback/test_flake8_command_callback.vader b/test/command_callback/test_flake8_command_callback.vader index 6297bd3..c275915 100644 --- a/test/command_callback/test_flake8_command_callback.vader +++ b/test/command_callback/test_flake8_command_callback.vader @@ -2,11 +2,13 @@ Before: Save g:ale_python_flake8_executable Save g:ale_python_flake8_options Save g:ale_python_flake8_use_global + Save g:ale_python_flake8_change_directory unlet! g:ale_python_flake8_executable unlet! g:ale_python_flake8_args unlet! g:ale_python_flake8_options unlet! g:ale_python_flake8_use_global + unlet! g:ale_python_flake8_change_directory let b:bin_dir = has('win32') ? 'Scripts' : 'bin' @@ -44,6 +46,13 @@ Execute(The flake8 callbacks should return the correct default values): \ . ale#Escape('flake8') . ' --format=default -', \ ale_linters#python#flake8#GetCommand(bufnr(''), ['2.9.9']) +Execute(The option for disabling changing directories should work): + let g:ale_python_flake8_change_directory = 0 + + AssertEqual + \ ale#Escape('flake8') . ' --format=default --stdin-display-name %s -', + \ ale_linters#python#flake8#GetCommand(bufnr(''), ['3.0.0']) + Execute(The flake8 command callback should let you set options): let g:ale_python_flake8_options = '--some-option'