summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/autoflake.vim28
-rw-r--r--doc/ale-python.txt28
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_autoflake_fixer_callback.vader49
-rwxr-xr-xtest/test-files/python/with_virtualenv/env/Scripts/autoflake.exe0
-rwxr-xr-xtest/test-files/python/with_virtualenv/env/bin/autoflake0
9 files changed, 113 insertions, 0 deletions
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 <circld1@gmail.com>
+" 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
diff --git a/doc/ale-python.txt b/doc/ale-python.txt
index 58b92dc9..6deff8f2 100644
--- a/doc/ale-python.txt
+++ b/doc/ale-python.txt
@@ -44,6 +44,33 @@ The first directory containing any of the files named above will be used.
===============================================================================
+autoflake *ale-python-autoflake*
+
+g:ale_python_autoflake_executable *g:ale_python_autoflake_executable*
+ *b:ale_python_autoflake_executable*
+ Type: |String|
+ Default: `'autoflake'`
+
+ See |ale-integrations-local-executables|
+
+
+g:ale_python_autoflake_options *g:ale_python_autoflake_options*
+ *b:ale_python_autoflake_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass extra options to autoflake.
+
+
+g:ale_python_autoflake_use_global *g:ale_python_autoflake_use_global*
+ *b:ale_python_autoflake_use_global*
+ Type: |Number|
+ Default: `get(g:, 'ale_use_global_executables', 0)`
+
+ See |ale-integrations-local-executables|
+
+
+===============================================================================
autoimport *ale-python-autoimport*
g:ale_python_autoimport_executable *g:ale_python_autoimport_executable*
@@ -69,6 +96,7 @@ g:ale_python_autoimport_use_global *g:ale_python_autoimport_use_glob
See |ale-integrations-local-executables|
+
===============================================================================
autopep8 *ale-python-autopep8*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 283caf06..d71d9354 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -399,6 +399,7 @@ Notes:
* `purescript-language-server`
* `purty`
* Python
+ * `autoflake`!!
* `autoimport`
* `autopep8`
* `bandit`
diff --git a/doc/ale.txt b/doc/ale.txt
index f2800ff0..1ec22c18 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2933,6 +2933,7 @@ documented in additional help files.
pyrex (cython)..........................|ale-pyrex-options|
cython................................|ale-pyrex-cython|
python..................................|ale-python-options|
+ autoflake.............................|ale-python-autoflake|
autoimport............................|ale-python-autoimport|
autopep8..............................|ale-python-autopep8|
bandit................................|ale-python-bandit|
diff --git a/supported-tools.md b/supported-tools.md
index d4e55f86..e823232b 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -408,6 +408,7 @@ formatting.
* [purescript-language-server](https://github.com/nwolverson/purescript-language-server)
* [purty](https://gitlab.com/joneshf/purty)
* Python
+ * [autoflake](https://github.com/myint/autoflake)
* [autoimport](https://lyz-code.github.io/autoimport/)
* [autopep8](https://github.com/hhatto/autopep8)
* [bandit](https://github.com/PyCQA/bandit) :warning:
diff --git a/test/fixers/test_autoflake_fixer_callback.vader b/test/fixers/test_autoflake_fixer_callback.vader
new file mode 100644
index 00000000..91fc62b5
--- /dev/null
+++ b/test/fixers/test_autoflake_fixer_callback.vader
@@ -0,0 +1,49 @@
+Before:
+ Save g:ale_python_autoflake_executable
+ Save g:ale_python_autoflake_options
+
+ " Use an invalid global executable, so we don't match it.
+ let g:ale_python_autoflake_executable = 'xxxinvalid'
+ let g:ale_python_autoflake_options = ''
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+ let g:dir = getcwd()
+
+ let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
+
+After:
+ Restore
+
+ unlet! b:bin_dir
+
+ call ale#test#RestoreDirectory()
+
+Execute(The autoflake callback should return the correct default values):
+ AssertEqual
+ \ 0,
+ \ ale#fixers#autoflake#Fix(bufnr(''))
+
+ silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/autoflake'))
+ \ . ' --in-place '
+ \ . ' %t',
+ \ 'read_temporary_file': 1,
+ \ },
+ \ ale#fixers#autoflake#Fix(bufnr(''))
+
+
+Execute(The autoflake callback should include options):
+ let g:ale_python_autoflake_options = '--some-option'
+
+ silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/autoflake'))
+ \ . ' --some-option'
+ \ . ' --in-place '
+ \ . ' %t',
+ \ 'read_temporary_file': 1,
+ \ },
+ \ ale#fixers#autoflake#Fix(bufnr(''))
diff --git a/test/test-files/python/with_virtualenv/env/Scripts/autoflake.exe b/test/test-files/python/with_virtualenv/env/Scripts/autoflake.exe
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/python/with_virtualenv/env/Scripts/autoflake.exe
diff --git a/test/test-files/python/with_virtualenv/env/bin/autoflake b/test/test-files/python/with_virtualenv/env/bin/autoflake
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/test-files/python/with_virtualenv/env/bin/autoflake