summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
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