From 3251d95a911af77feb34153b76d0d5415130e724 Mon Sep 17 00:00:00 2001 From: Derek P Sifford Date: Wed, 4 Jul 2018 13:01:16 -0400 Subject: [PATCH 1/3] add options variable to isort --- autoload/ale/fixers/isort.vim | 4 +++- doc/ale-python.txt | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index 74ba3bc8..acfbe14a 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -5,6 +5,8 @@ call ale#Set('python_isort_executable', 'isort') call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0)) function! ale#fixers#isort#Fix(buffer) abort + let l:options = ale#Var(a:buffer, 'python_isort_options') + let l:executable = ale#python#FindExecutable( \ a:buffer, \ 'python_isort', @@ -17,6 +19,6 @@ function! ale#fixers#isort#Fix(buffer) abort return { \ 'command': ale#path#BufferCdString(a:buffer) - \ . ale#Escape(l:executable) . ' -', + \ . ale#Escape(l:executable) . ' ' . l:options . ' -', \} endfunction diff --git a/doc/ale-python.txt b/doc/ale-python.txt index de706896..1c71dad2 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -145,6 +145,14 @@ g:ale_python_isort_executable *g:ale_python_isort_executable* See |ale-integrations-local-executables| +g:ale_python_isort_options *g:ale_python_isort_options* + *b:ale_python_isort_options* + Type: |String| + Default: `''` + + This variable can be set to pass extra options to isort. + + g:ale_python_isort_use_global *g:ale_python_isort_use_global* *b:ale_python_isort_use_global* Type: |Number| From 6dc69b2144f567072b9ff757a68de166717b9acf Mon Sep 17 00:00:00 2001 From: Derek P Sifford Date: Wed, 4 Jul 2018 21:16:57 -0400 Subject: [PATCH 2/3] address code review issues --- autoload/ale/fixers/isort.vim | 3 ++- test/fixers/test_isort_fixer_callback.vader | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim index acfbe14a..9070fb27 100644 --- a/autoload/ale/fixers/isort.vim +++ b/autoload/ale/fixers/isort.vim @@ -2,6 +2,7 @@ " Description: Fixing Python imports with isort. call ale#Set('python_isort_executable', 'isort') +call ale#Set('python_isort_options', '') call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0)) function! ale#fixers#isort#Fix(buffer) abort @@ -19,6 +20,6 @@ function! ale#fixers#isort#Fix(buffer) abort return { \ 'command': ale#path#BufferCdString(a:buffer) - \ . ale#Escape(l:executable) . ' ' . l:options . ' -', + \ . ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') . ' -', \} endfunction diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader index 7c2b515f..56c08d26 100644 --- a/test/fixers/test_isort_fixer_callback.vader +++ b/test/fixers/test_isort_fixer_callback.vader @@ -1,5 +1,6 @@ Before: Save g:ale_python_isort_executable + Save g:ale_python_isort_options " Use an invalid global executable, so we don't match it. let g:ale_python_isort_executable = 'xxxinvalid' @@ -30,3 +31,19 @@ Execute(The isort callback should return the correct default values): \ . ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/isort')) . ' -', \ }, \ ale#fixers#isort#Fix(bufnr('')) + +Execute(The isort callback should respect custom options): + let g:ale_python_isort_options = '--multi-line=3 --trailing-comma' + + AssertEqual + \ 0, + \ ale#fixers#isort#Fix(bufnr('')) + + silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py') + AssertEqual + \ { + \ 'command': 'cd ' . ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir/foo')) . ' && ' + \ . ale#Escape(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/isort')) + \ . ' --multi-line=3 --trailing-comma -', + \ }, + \ ale#fixers#isort#Fix(bufnr('')) From b8591e1034abdccd3e9c960da20d5fa276fd90a0 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 5 Jul 2018 09:24:57 +0100 Subject: [PATCH 3/3] Fix the doctag alignment --- doc/ale-python.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ale-python.txt b/doc/ale-python.txt index 1c71dad2..be8ad118 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -145,8 +145,8 @@ g:ale_python_isort_executable *g:ale_python_isort_executable* See |ale-integrations-local-executables| -g:ale_python_isort_options *g:ale_python_isort_options* - *b:ale_python_isort_options* +g:ale_python_isort_options *g:ale_python_isort_options* + *b:ale_python_isort_options* Type: |String| Default: `''`