summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorJack Evans <jack@evans.gb.net>2018-04-06 10:08:25 +0100
committerw0rp <w0rp@users.noreply.github.com>2018-04-06 11:08:25 +0200
commitc5d3af04fced61a654029a07139faa365c4a8534 (patch)
treef75aea22a44d8324c17cbf84eba60d234c53edfc /autoload
parent85a2a008266f69847a3c7a9d38c16b779636ab30 (diff)
downloadale-c5d3af04fced61a654029a07139faa365c4a8534.zip
Added support for Python black fixer (#1451)
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/black.vim26
2 files changed, 31 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 4c0703a5..86a10908 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 PEP8 issues with autopep8.',
\ },
+\ 'black': {
+\ 'function': 'ale#fixers#black#Fix',
+\ 'suggested_filetypes': ['python'],
+\ 'description': 'Fix PEP8 issues with black.',
+\ },
\ 'prettier_standard': {
\ 'function': 'ale#fixers#prettier_standard#Fix',
\ 'suggested_filetypes': ['javascript'],
diff --git a/autoload/ale/fixers/black.vim b/autoload/ale/fixers/black.vim
new file mode 100644
index 00000000..6f6d56f3
--- /dev/null
+++ b/autoload/ale/fixers/black.vim
@@ -0,0 +1,26 @@
+" Author: w0rp <devw0rp@gmail.com>
+" Description: Fixing Python files with black.
+"
+call ale#Set('python_black_executable', 'black')
+call ale#Set('python_black_use_global', 0)
+call ale#Set('python_black_options', '')
+
+function! ale#fixers#black#Fix(buffer) abort
+ let l:executable = ale#python#FindExecutable(
+ \ a:buffer,
+ \ 'python_black',
+ \ ['black'],
+ \)
+
+ if !executable(l:executable)
+ return 0
+ endif
+
+ let l:options = ale#Var(a:buffer, 'python_black_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' -',
+ \}
+endfunction