From e80389f8d453c610e9d6f7c1acf7085ad77abc19 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 19 May 2017 15:24:41 +0100 Subject: [PATCH] Add some more tools for fixing problems with Python files --- autoload/ale/fix/registry.vim | 22 +++++++++++++++++++++- autoload/ale/handlers/python.vim | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index b0f87ddc..e524e136 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -2,10 +2,30 @@ " Description: A registry of functions for fixing things. let s:default_registry = { +\ 'autopep8': { +\ 'function': 'ale#handlers#python#AutoPEP8', +\ 'suggested_filetypes': ['python'], +\ 'description': 'Fix PEP8 issues with autopep8.', +\ }, \ 'eslint': { \ 'function': 'ale#handlers#eslint#Fix', \ 'suggested_filetypes': ['javascript'], -\ 'description': '', +\ 'description': 'Apply eslint --fix to a file.', +\ }, +\ 'isort': { +\ 'function': 'ale#handlers#python#ISort', +\ 'suggested_filetypes': ['python'], +\ 'description': 'Sort Python imports with isort.', +\ }, +\ 'remove_trailing_lines': { +\ 'function': 'ale#fix#generic#RemoveTrailingBlankLines', +\ 'suggested_filetypes': [], +\ 'description': 'Remove all blank lines at the end of a file.', +\ }, +\ 'yapf': { +\ 'function': 'ale#handlers#python#YAPF', +\ 'suggested_filetypes': ['python'], +\ 'description': 'Fix Python files with yapf.', \ }, \} diff --git a/autoload/ale/handlers/python.vim b/autoload/ale/handlers/python.vim index 33ee3c9d..5e9ddecd 100644 --- a/autoload/ale/handlers/python.vim +++ b/autoload/ale/handlers/python.vim @@ -41,3 +41,25 @@ function! ale#handlers#python#AutoPEP8(buffer, lines) abort \ 'command': 'autopep8 -' \} endfunction + +function! ale#handlers#python#ISort(buffer, lines) abort + let l:config = ale#path#FindNearestFile(a:buffer, '.isort.cfg') + let l:config_options = !empty(l:config) + \ ? ' --settings-path ' . ale#Escape(l:config) + \ : '' + + return { + \ 'command': 'isort' . l:config_options . ' -', + \} +endfunction + +function! ale#handlers#python#YAPF(buffer, lines) abort + let l:config = ale#path#FindNearestFile(a:buffer, '.style.yapf') + let l:config_options = !empty(l:config) + \ ? ' --style ' . ale#Escape(l:config) + \ : '' + + return { + \ 'command': 'yapf --no-local-style' . l:config_options, + \} +endfunction