From 82a7e9f5889c13021ff61f8dc80b57348318c449 Mon Sep 17 00:00:00 2001 From: Nikolay Zakirov Date: Tue, 13 Jul 2021 17:58:18 +0500 Subject: add autoflake fixer (#3779) * first attempt * added autoflake executable * added Windows executable for appveyor * delete unused files * corrected wrong sorting --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/autoflake.vim | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 autoload/ale/fixers/autoflake.vim (limited to 'autoload') diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 728b6df7..45518904 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -17,6 +17,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['python'], \ 'description': 'Fix import issues with autoimport.', \ }, +\ 'autoflake': { +\ 'function': 'ale#fixers#autoflake#Fix', +\ 'suggested_filetypes': ['python'], +\ 'description': 'Fix flake issues with autoflake.', +\ }, \ 'autopep8': { \ 'function': 'ale#fixers#autopep8#Fix', \ 'suggested_filetypes': ['python'], diff --git a/autoload/ale/fixers/autoflake.vim b/autoload/ale/fixers/autoflake.vim new file mode 100644 index 00000000..e2ad6536 --- /dev/null +++ b/autoload/ale/fixers/autoflake.vim @@ -0,0 +1,28 @@ +" Author: circld +" Description: Fixing files with autoflake. + +call ale#Set('python_autoflake_executable', 'autoflake') +call ale#Set('python_autoflake_use_global', get(g:, 'ale_use_global_executables', 0)) +call ale#Set('python_autoflake_options', '') + +function! ale#fixers#autoflake#Fix(buffer) abort + let l:executable = ale#python#FindExecutable( + \ a:buffer, + \ 'python_autoflake', + \ ['autoflake'], + \) + + if !executable(l:executable) + return 0 + endif + + let l:options = ale#Var(a:buffer, 'python_autoflake_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' --in-place ' + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction -- cgit v1.2.3