Move all functions for fixing things to autoload/ale/fixers, and only accept the lines of input where needed.

This commit is contained in:
w0rp
2017-06-07 14:02:29 +01:00
parent edddb1910b
commit 7517fd8226
15 changed files with 132 additions and 98 deletions
+8
View File
@@ -0,0 +1,8 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing files with autopep8.
function! ale#fixers#autopep8#Fix(buffer) abort
return {
\ 'command': 'autopep8 -'
\}
endfunction
+36
View File
@@ -0,0 +1,36 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing files with eslint.
function! s:FindConfig(buffer) abort
for l:filename in [
\ '.eslintrc.js',
\ '.eslintrc.yaml',
\ '.eslintrc.yml',
\ '.eslintrc.json',
\ '.eslintrc',
\]
let l:config = ale#path#FindNearestFile(a:buffer, l:filename)
if !empty(l:config)
return l:config
endif
endfor
return ''
endfunction
function! ale#fixers#eslint#Fix(buffer) abort
let l:executable = ale#handlers#eslint#GetExecutable(a:buffer)
let l:config = s:FindConfig(a:buffer)
if empty(l:config)
return 0
endif
return {
\ 'command': ale#Escape(l:executable)
\ . ' --config ' . ale#Escape(l:config)
\ . ' --fix %t',
\ 'read_temporary_file': 1,
\}
endfunction
+12
View File
@@ -0,0 +1,12 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Generic functions for fixing files with.
function! ale#fix#generic#RemoveTrailingBlankLines(buffer, lines) abort
let l:end_index = len(a:lines) - 1
while l:end_index > 0 && empty(a:lines[l:end_index])
let l:end_index -= 1
endwhile
return a:lines[:l:end_index]
endfunction
+22
View File
@@ -0,0 +1,22 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Generic fixer functions for Python.
" Add blank lines before control statements.
function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, lines) abort
let l:new_lines = []
let l:last_indent_size = 0
for l:line in a:lines
let l:indent_size = len(matchstr(l:line, '^ *'))
if l:indent_size <= l:last_indent_size
\&& match(l:line, '\v^ *(return|if|for|while|break|continue)') >= 0
call add(l:new_lines, '')
endif
call add(l:new_lines, l:line)
let l:last_indent_size = l:indent_size
endfor
return l:new_lines
endfunction
+13
View File
@@ -0,0 +1,13 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing Python imports with isort.
function! ale#fixers#isort#Fix(buffer) 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
+25
View File
@@ -0,0 +1,25 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
" w0rp <devw0rp@gmail.com>
" Description: Integration of Prettier with ALE.
call ale#Set('javascript_prettier_executable', 'prettier')
call ale#Set('javascript_prettier_use_global', 0)
function! ale#handlers#prettier#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier', [
\ 'node_modules/prettier-cli/index.js',
\ 'node_modules/.bin/prettier',
\])
endfunction
function! ale#handlers#prettier#Fix(buffer, lines) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_options')
return {
\ 'command': ale#Escape(ale#handlers#prettier#GetExecutable(a:buffer))
\ . ' %t'
\ . ' ' . l:options
\ . ' --write',
\ 'read_temporary_file': 1,
\}
endfunction
+25
View File
@@ -0,0 +1,25 @@
" Author: tunnckoCore (Charlike Mike Reagent) <mameto2011@gmail.com>,
" w0rp <devw0rp@gmail.com>
" Description: Integration between Prettier and ESLint.
call ale#Set('javascript_prettier_eslint_executable', 'prettier-eslint')
call ale#Set('javascript_prettier_eslint_use_global', 0)
function! ale#handlers#prettier_eslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [
\ 'node_modules/prettier-eslint-cli/index.js',
\ 'node_modules/.bin/prettier-eslint',
\])
endfunction
function! ale#handlers#prettier_eslint#Fix(buffer, lines) abort
let l:options = ale#Var(a:buffer, 'javascript_prettier_eslint_options')
return {
\ 'command': ale#Escape(ale#handlers#prettier_eslint#GetExecutable(a:buffer))
\ . ' %t'
\ . ' ' . l:options
\ . ' --write',
\ 'read_temporary_file': 1,
\}
endfunction
+13
View File
@@ -0,0 +1,13 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing Python files with yapf.
function! ale#fixers#yapf#Fix(buffer) 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