diff options
author | infokiller <infokiller@users.noreply.github.com> | 2022-06-16 16:41:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 22:41:57 +0900 |
commit | 91e8422d6d67f1b1139b57b8707945ea2531443e (patch) | |
tree | 1b1e68ba25995720c42e73d616d88ea04eec95c1 /autoload | |
parent | f10349b48b173d50b523ce009934bb4bfba04f7f (diff) | |
download | ale-91e8422d6d67f1b1139b57b8707945ea2531443e.zip |
Add pyflyby fixer (using its tidy-imports script) (#4219)
* add pyflyby fixer
updates
* pyflyby: add docs
updates
* add tests to pyflyby fixer
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/pyflyby.vim | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 2e772419..57fff655 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -136,6 +136,11 @@ let s:default_registry = { \ 'description': 'Apply prettier-eslint to a file.', \ 'aliases': ['prettier-eslint'], \ }, +\ 'pyflyby': { +\ 'function': 'ale#fixers#pyflyby#Fix', +\ 'suggested_filetypes': ['python'], +\ 'description': 'Tidy Python imports with pyflyby.', +\ }, \ 'importjs': { \ 'function': 'ale#fixers#importjs#Fix', \ 'suggested_filetypes': ['javascript'], diff --git a/autoload/ale/fixers/pyflyby.vim b/autoload/ale/fixers/pyflyby.vim new file mode 100644 index 00000000..81c0f05e --- /dev/null +++ b/autoload/ale/fixers/pyflyby.vim @@ -0,0 +1,41 @@ +" Author: infokiller <joweill@icloud.com> +" Description: Tidy imports using pyflyby's tidy-import script +" https://github.com/deshaw/pyflyby + +call ale#Set('python_pyflyby_executable', 'tidy-imports') +call ale#Set('python_pyflyby_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('python_pyflyby_options', '') +call ale#Set('python_pyflyby_auto_pipenv', 0) +call ale#Set('python_pyflyby_auto_poetry', 0) + +function! ale#fixers#pyflyby#GetExecutable(buffer) abort + if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyflyby_auto_pipenv')) + \ && ale#python#PipenvPresent(a:buffer) + return 'pipenv' + endif + + if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyflyby_auto_poetry')) + \ && ale#python#PoetryPresent(a:buffer) + return 'poetry' + endif + + return ale#python#FindExecutable(a:buffer, 'python_pyflyby', ['tidy-imports']) +endfunction + +function! ale#fixers#pyflyby#Fix(buffer) abort + " let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer) + let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer) + let l:cmd = [ale#Escape(l:executable)] + + if l:executable =~? 'pipenv\|poetry$' + call extend(l:cmd, ['run', 'tidy-imports']) + endif + + let l:options = ale#Var(a:buffer, 'python_pyflyby_options') + + if !empty(l:options) + call add(l:cmd, l:options) + endif + + return {'command': join(l:cmd, ' ')} +endfunction |