diff options
author | Jake Kaufman <me@jake.computer> | 2019-06-05 23:18:33 -0400 |
---|---|---|
committer | Jake Kaufman <me@jake.computer> | 2019-06-08 19:22:50 -0400 |
commit | 56641e02301475cfee9ddcaf547066898f073048 (patch) | |
tree | 3b297ebff78b4d0794f62172510adb83ae2e0ce8 /autoload | |
parent | 7b78f2b846e2f3443dcb2ceacee54eb99e37f040 (diff) | |
download | ale-56641e02301475cfee9ddcaf547066898f073048.zip |
Add support for reorder-python-imports fixer
isort is great, but I've come to prefer reorder-python-imports. The tool
has a focus on smaller diffs than isort. reorder-python-imports is also
a little smarter than isort which is nice.
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/reorder_python_imports.vim | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 925181ca..f7bd3af6 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -310,6 +310,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['sql'], \ 'description': 'A PostgreSQL SQL syntax beautifier', \ }, +\ 'reorder-python-imports': { +\ 'function': 'ale#fixers#reorder_python_imports#Fix', +\ 'suggested_filetypes': ['python'], +\ 'description': 'Sort Python imports with reorder-python-imports.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/reorder_python_imports.vim b/autoload/ale/fixers/reorder_python_imports.vim new file mode 100644 index 00000000..42a0a6e2 --- /dev/null +++ b/autoload/ale/fixers/reorder_python_imports.vim @@ -0,0 +1,25 @@ +" Author: jake <me@jake.computer> +" Description: Fixing Python imports with reorder-python-imports. + +call ale#Set('python_reorder_python_imports_executable', 'reorder-python-imports') +call ale#Set('python_reorder_python_imports_options', '') +call ale#Set('python_reorder_python_imports_use_global', get(g:, 'ale_use_global_executables', 0)) + +function! ale#fixers#reorder_python_imports#Fix(buffer) abort + let l:executable = ale#python#FindExecutable( + \ a:buffer, + \ 'python_reorder_python_imports', + \ ['reorder-python-imports'], + \) + + if !executable(l:executable) + return 0 + endif + + let l:options = ale#Var(a:buffer, 'python_reorder_python_imports_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') . ' -', + \} +endfunction |